-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Exception e wrote:
> 
> Brenton Alker-3 wrote:
>>  solve.
>>
>> 1. How would I persist this information?
>> The start date is easy, it's just a date.
>> The interval I'm not sure about. A number of seconds (or days if it's
>> only accurate to date) could work for basic things like every week. But
>> what about irregular things like every month, or even more complex
>> values eg. "The first Sunday of the month"?
>>
> 
> If the timespans are really complex, in essence: can not be catched in a
> limited amount of time values, you will always need to have an algorithm
> that designates the interval.
> So I would associate constants to those algorithms. In many databases you
> can create enumerated types for example.
> 
> event_interval: {FIRST_MONDAY_MONTH, FIRST_TUESDAY_MONTH, FIRST_DAY_YEAR,
> etc}
> 
> 
> store an event like: "My event", "John", "2009-08-21", FIRST_MONDAY_MONTH
> 
> In your logic, be it php or a self written mysql function for example, you
> would get the actual value based on the interval constant.

That would require essentially hard coded all possible date allocations,
which isn't very flexible.

> Simple things like "next saturday", "+1 month" are understood by php date
> functions (http://php.net/manual/en/function.strtotime.php)
> 
> $d = new DateTime('next saturday');
> echo $d->format('d, F Y'); //works!

True, but I'm not sure that's too helpful in this case.

> 
> I think you might even be able to bypass the constants if you would have a
> interval scheme like this
> 
> table: interval_when
> year,  month,  week_year,  week_month,  day_month, day_week
> ----------------------------------------
> null   null      null               null               null            7      
>            
> ==> means: every sunday
> 2009 null      null               null               null            7        
>          
> ==> means: every sunday in 2009
> null   null      null               1                  null            7      
>            
> ==> means: every first sunday of the month
> 
> Translating a record from this to an actual date might require one generic
> function.

This is essentially what I am doing now, basically modeled after crontab
as I originally mentioned. I've only got a column for day, month and
weekday so far, but it is easy to add additional columns at a later date
as requirements become more complex.

Finding the next date is currently a matter of looping through the days
and seeing if they match all criteria (limited to checking one year
ahead to prevent an infinite loop). That part can probably be refactored
later, but it works for now.

- --

Brenton Alker
PHP Developer - Brisbane, Australia

http://blog.tekerson.com/
http://twitter.com/tekerson

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrk6tsACgkQ7bkAtAithuuNDACfcFMtH2GEyMZ5zl+hnvoHOD6D
tSMAoJbTyre5eSp/zD0QcVrYJEqBL6rX
=ELBM
-----END PGP SIGNATURE-----

Reply via email to