John Machin wrote:
> I don't understand. The examples that I showed went from the last day
> of a month to the last day of another month. [...]
Q1: is ((date-4days)+4days) == date?
Q2: is (((date-4days)+1month)+4days) == date+1month?
Ok, let's use Python'ish syntax (including numbering the days f
thebjorn wrote:
> John Machin wrote:
> > Jan 31 to Feb 27: 27d (ex) 28d (in)
> > Jan 31 to Feb 28: 28d (ex) 1m 1d (in)
> > Jan 31 to Mar 01: 1m 1d (ex) 1m 2d (in)
> > So 1 day short of 1m 1d is not 1m 0 d???
>
> Exactly. Just as a person born on 1999-3-1 isn't a year old on
> 2000-2-29. Perfectly
John Machin wrote:
> Jan 31 to Feb 27: 27d (ex) 28d (in)
> Jan 31 to Feb 28: 28d (ex) 1m 1d (in)
> Jan 31 to Mar 01: 1m 1d (ex) 1m 2d (in)
> So 1 day short of 1m 1d is not 1m 0 d???
Exactly. Just as a person born on 1999-3-1 isn't a year old on
2000-2-29. Perfectly regular, consistent and reasonab
thebjorn wrote:
> Bruno Desthuilliers wrote:
>> Which conversion ? How do you get the data ? as a datetime object ? as a
>> (y,m,d) tuple ? as a "y-m-d" string ? Else ?
>
> All input routines, whether they're from a web-form, database, command
> line, or anywhere else, only produce objects from th
thebjorn wrote:
> John Machin wrote:
> > thebjorn wrote:
> [...]
> > > You give a good argument that the concept of a month is fuzzy
> >
> > Sorry, I can't imagine where you got "fuzzy" from. Perhaps you mean
> > some other word. The concept is capable of being expressed precisely.
>
> and the se
Bruno Desthuilliers wrote:
> Which conversion ? How do you get the data ? as a datetime object ? as a
> (y,m,d) tuple ? as a "y-m-d" string ? Else ?
All input routines, whether they're from a web-form, database, command
line, or anywhere else, only produce objects from the datetime module
for cale
John Machin wrote:
> thebjorn wrote:
[...]
> > You give a good argument that the concept of a month is fuzzy
>
> Sorry, I can't imagine where you got "fuzzy" from. Perhaps you mean
> some other word. The concept is capable of being expressed precisely.
and the second to last date in January plus
thebjorn wrote:
> John Machin wrote:
> > thebjorn wrote:
> > > John Machin wrote:
> > > > thebjorn wrote:
> [...]
> > > > Holy code bloat, Batman! Try this:
> > > >
> > > > return now.year - born.year - (birthday > now)
> > >
> > > yuck :-)
> >
> > But this:
> > return now.year - born.year
John Machin wrote:
> thebjorn wrote:
> > John Machin wrote:
> > > thebjorn wrote:
[...]
> > > Holy code bloat, Batman! Try this:
> > >
> > > return now.year - born.year - (birthday > now)
> >
> > yuck :-)
>
> But this:
> return now.year - born.year - (birthday > now and 1 or 0) is not yuck?
thebjorn wrote:
> Bruno Desthuilliers wrote:
> [...]
>
>>Possible solution:
>>
>>import mx.DateTime as dt
>>def age(date):
>>return dt.Age(dt.today(), date).years
>>born = dt.Date(1967, 5, 1)
>>assert age(born) == 39
>
>
> dealbreaker:
>
age(datetime.date(1970,5,2))
>
(snip traceback)
W
thebjorn wrote:
> John Machin wrote:
> > thebjorn wrote:
> [...]
> > >
> > > def age(born):
> > > now = date.today()
> > > birthday = date(now.year, born.month, born.day)
> >
> > Bad luck if the punter was born on 29 Feb and the current year is not a
> > leap year.
>
> Good catch! Tha
On 2006-07-26 17:50:43, thebjorn wrote:
> I don't agree that the irregular sized months cause a problem in this
> case. They do cause a problem if you're asking "when is today + one
> month?", i.e. there isn't an unambiguous answer to that question in
> general (e.g. if today was January 31). We'r
Bruno Desthuilliers wrote:
[...]
> Possible solution:
>
> import mx.DateTime as dt
> def age(date):
> return dt.Age(dt.today(), date).years
> born = dt.Date(1967, 5, 1)
> assert age(born) == 39
dealbreaker:
>>> age(datetime.date(1970,5,2))
Traceback (most recent call last):
File "", line 1,
John Machin wrote:
> thebjorn wrote:
[...]
> >
> > def age(born):
> > now = date.today()
> > birthday = date(now.year, born.month, born.day)
>
> Bad luck if the punter was born on 29 Feb and the current year is not a
> leap year.
Good catch! Thanks!
[..]
> Holy code bloat, Batman! T
Roy Smith wrote:
> "thebjorn" <[EMAIL PROTECTED]> wrote:
>
> > def age(born):
> > now = date.today()
> > birthday = date(now.year, born.month, born.day)
> > return now.year - born.year - (birthday > now and 1 or 0)
>
> I don't get that last line. There's two things in particula
John Machin wrote:
> Bruno Desthuilliers wrote:
>
>>John Machin wrote:
>>
>>>Bruno Desthuilliers wrote:
>>
>>>Which pieces of the following seem to be working to you?
>>
>>John, it seems you failed to notice the use of "may" and "seems" in my
>>post. IIRC, both are supposed to strongly suggest a l
Roy Smith:
> 2) I find the "and 1 or 0" part very confusing. I can't remember all the
> minor rules about operator precedence, but I'm sure this works out to some
> clever hack involving boolean short-circuit evaluation to get around the
> lack of a ternary operator in python. If I need to pull o
Bruno Desthuilliers wrote:
> John Machin wrote:
> > Bruno Desthuilliers wrote:
>
> >
> > Which pieces of the following seem to be working to you?
>
> John, it seems you failed to notice the use of "may" and "seems" in my
> post. IIRC, both are supposed to strongly suggest a lack of certitude.
>
>
John Machin wrote:
> Bruno Desthuilliers wrote:
>
>>thebjorn wrote:
>>
>>>For the purpose of finding someone's age I was looking for a way to
>>>find how the difference in years between two dates, so I could do
>>>something like:
>>>
>>> age = (date.today() - born).year
>>>
>>>but that didn't wor
Bruno Desthuilliers wrote:
> thebjorn wrote:
> > For the purpose of finding someone's age I was looking for a way to
> > find how the difference in years between two dates, so I could do
> > something like:
> >
> > age = (date.today() - born).year
> >
> > but that didn't work (the timedelta class
"thebjorn" <[EMAIL PROTECTED]> wrote:
> def age(born):
> now = date.today()
> birthday = date(now.year, born.month, born.day)
> return now.year - born.year - (birthday > now and 1 or 0)
I don't get that last line. There's two things in particular that are
puzzling me.
1) Wh
thebjorn wrote:
> For the purpose of finding someone's age I was looking for a way to
> find how the difference in years between two dates, so I could do
> something like:
>
> age = (date.today() - born).year
>
> but that didn't work (the timedelta class doesn't have a year
> accessor).
>
> I
thebjorn wrote:
> For the purpose of finding someone's age I was looking for a way to
> find how the difference in years between two dates, so I could do
> something like:
>
> age = (date.today() - born).year
>
> but that didn't work (the timedelta class doesn't have a year
> accessor).
>
> I loo
For the purpose of finding someone's age I was looking for a way to
find how the difference in years between two dates, so I could do
something like:
age = (date.today() - born).year
but that didn't work (the timedelta class doesn't have a year
accessor).
I looked in the docs and the cookbook,
24 matches
Mail list logo