[date time] are months and years derived from date_duration?
Hi I have simple problem if months and years derived from date_duration? The goal is that user can dynamically choose a time of events that appear periodically in shedule e.g. every 20th of any month is a meeting or every 3 months something other happens or birthsday is one per year. Regards. -- |\/\/| Seweryn Habdank-Wojewódzki \/\/
Seweryn Habdank-Wojewódzki wrote:
Hi
I have simple problem if months and years derived from date_duration?
The goal is that user can dynamically choose a time of events that appear periodically in shedule e.g. every 20th of any month is a meeting or every 3 months something other happens or birthsday is one per year.
I'm not entirely sure I understand your question, but it sounds to me like you want to use date generators. These allow you to specify part of a date and then generate a concrete date based on a final input. For example you can say partial_date pd(20, Jan); date d = pd.get_date(2007); Is that what you are trying to do? Anyway, the docs for this stuff are at: http://www.boost.org/doc/html/date_time/gregorian.html#date_time.gregorian.d... Jeff
Hi Thanks for reply.
I'm not entirely sure I understand your question, but it sounds to me like you want to use date generators. These allow you to specify part of a date and then generate a concrete date based on a final input. For example you can say
partial_date pd(20, Jan); date d = pd.get_date(2007);
Is that what you are trying to do?
More less. This (above) is a partial functionality. Please consider somethig like setting up the schedule. You are open the organizer (virtual or paper one). And you know that every month in 20 you have to go somewhere. And you mark (in organizer) the day 20 in any month, then "click" on option every month, and there is created list of all days which satisfies that, form the point to the end of organizer (let's say in 2020). Generation is easy, but the problem is that in particular situation user can choose modifiers: 1. every week (it is easy because it is always 7 days, however there is a type boost::gregorian::weeks); 2. every month (not easy because lengths of months are different, and for that fact there is a special type b...::g...::months) 3. every year (type b...::g...::years) 4. other period (user can put any value in days how often he/she have to do something) for example every 2 days user have to water flowers. So to summarize I know one exact date (clicked one), and I want to generate others. Below is small example: bg::date const final_date(2020,12,31); bg::months const every_month(1); // this TYPE is variable in runtime bg::date d0(2007,3,4); do { d0 += every_month; cout << d0 << '\n'; } while (d0 < final_date); I am trying to use boost::variant for that purpose. Regards. -- |\/\/| Seweryn Habdank-Wojewódzki \/\/
On Sun, 27 May 2007 21:06:09 +0200, Seweryn Habdank-Wojewódzki wrote
So to summarize I know one exact date (clicked one), and I want to generate others. Below is small example:
bg::date const final_date(2020,12,31); bg::months const every_month(1); // this TYPE is variable in runtime bg::date d0(2007,3,4); do { d0 += every_month; cout << d0 << '\n'; } while (d0 < final_date);
I am trying to use boost::variant for that purpose.
Ok, I would suggest you take a look at the date_iterator -- I think this will provide the framework you need. The library provides basically 4 variations on the date_iterator - month_iterator, year_iterator, week_iterator, and day_iterator. These take a date as a starting point and will then calculate the next increment. so you can change your code to something like: month_iterator itr(date(2007,3,4)); //the following code is generic and would work with a date, week, //month, or year iterator. do { itr++; cout << *itr << '\n'; } while (itr < final_date); It turns out that you can use the base type date_itr_baseboost::gregorian::date to virtually dispatch. You can also replace the functor in the iterators to create your own logic if you want. You can look at the examples/test and source for more details. Jeff
Hi Thanks for reply.
Ok, I would suggest you take a look at the date_iterator -- I think this will provide the framework you need.
Yes, that is what I need :-). Thanks a lot. Regards. -- |\/\/| Seweryn Habdank-Wojewódzki \/\/
Hi
It turns out that you can use the base type date_itr_baseboost::gregorian::date to virtually dispatch. You can also replace the functor in the iterators to create your own logic if you want. You can look at the examples/test and source for more details.
BTW. Do you know how to clone this iterator in dynamic context? There is no such a functionality given in date_iterator class. I mean that in base class can be e.g. clone() method, which calls private e.g. do_clone() methods in derived classes. date_iterator is not declared as noncopyable: http://www.boost.org/doc/html/boost/date_time/date_itr_base.html Regards. -- |\/\/| Seweryn Habdank-Wojewódzki \/\/
participants (2)
-
Jeff Garland
-
Seweryn Habdank-Wojewódzki