Re: prefixes and namespaces?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Jeremy Cowgar wrote:
> }}}
<eucode>
> dt = d:add(dt, 3 * HOURS)
> dt = d:add(dt, 3 * WEEKS)
> dt = d:add(dt, 7 * DAYS)
> dt = d:subtract(dt, 30 * DAYS)
> dt = d:subtract(dt, 12.5 * HOURS)
> </eucode>
{{{

> 
> Note, I did not add YEARS as it is not a fixed unit. To do that correctly we
> would need to add a function add_years, which accounts for leap year.


I don't think that using multiplication like this is a good solution. 
We will not be able to add MONTHS and YEARS. Why do we omit months and years
if we can write HOURS MINUTES DAYS and WEEKS ?

Year and Month addition is more tricky, I will take examples from mysql.

+-----------------------------------------+
| date_add('2008-4-25', interval 1 month) |
+-----------------------------------------+
| 2008-05-25                              |
+-----------------------------------------+

+-----------------------------------------+
| date_add('2008-5-25', interval 1 month) |
+-----------------------------------------+
| 2008-06-25                              |
+-----------------------------------------+
So "1 month" is not translated to 30 or 31 days but it directly 
modifies based on the original date.


+-----------------------------------------+
| date_add('2008-5-31', interval 1 month) |
+-----------------------------------------+
| 2008-06-30                              |
+-----------------------------------------+
If the result is an invalid date, it is adjusted.

+----------------------------------------+
| date_add('2008-2-29', interval 1 year) |
+----------------------------------------+
| 2009-02-28                             |
+----------------------------------------+
The same goes for year.

+-----------------------------------------+
| date_add('2008-2-29', interval -1 year) |
+-----------------------------------------+
| 2007-02-28                              |
+-----------------------------------------+
Subtraction has the same result.

+-----------------------------------------+
| date_add('2008-2-29',interval 1.5 hour) |
+-----------------------------------------+
| 2008-02-29 02:00:00                     |
+-----------------------------------------+
No fractions allowed. Really important! Because how can we define 0.5 months or
0.5 years etc. Will be very messy.

...

So in order to accomodate year and month add/sub, why don't we make it

dt = d:add(dt, 3, HOURS)
dt = d:add(dt, 3, WEEKS)
dt = d:add(dt, 7, DAYS)
dt = d:add(dt, -30, MONTHS)
dt = d:add(dt, -12, YEARS)


1. I think subtract is not necessary, just use minus.

2. No fractions allowed except for SECONDS.

If fractions were allowed, d:add(dt, 1/6, HOURS) may not be 
equal to d:add(dt, 10, MINUTES) because of the floating point error.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu