Re: mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

2009-10-12 Thread greg

MRAB wrote:


And when someone says January 30, do they really mean the day before
the last day of the month?


No, no, that's January -2, a *completely* different thing!

--
Greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

2009-10-12 Thread Piet van Oostrum
 greg g...@cosc.canterbury.ac.nz (g) wrote:

g MRAB wrote:
 And when someone says January 30, do they really mean the day before
 the last day of the month?

g No, no, that's January -2, a *completely* different thing!

But for someone else it would be February -2.
-- 
Piet van Oostrum p...@vanoostrum.org
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

2009-10-12 Thread Chris Rebert
On Mon, Oct 12, 2009 at 4:27 AM, Piet van Oostrum p...@cs.uu.nl wrote:
 greg g...@cosc.canterbury.ac.nz (g) wrote:

g MRAB wrote:
 And when someone says January 30, do they really mean the day before
 the last day of the month?

g No, no, that's January -2, a *completely* different thing!

 But for someone else it would be February -2.

And for still others, it's the last $DAYOFWEEK of the month, which
just happened to fall on the 30th.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

2009-10-12 Thread MRAB

Piet van Oostrum wrote:

greg g...@cosc.canterbury.ac.nz (g) wrote:



g MRAB wrote:

And when someone says January 30, do they really mean the day before
the last day of the month?



g No, no, that's January -2, a *completely* different thing!


But for someone else it would be February -2.


When is February 0? :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

2009-10-12 Thread M.-A. Lemburg
Tim Chase wrote:
 Month arithmetic is a bit of a mess, since it's not clear how
 to map e.g. Jan 31 + one month.
 
 Jan 31 + one month usually means add one to the month value and then
 keep backing off the day if you get an exception making the date, so
 you'd get Feb 31, exception, Feb 30, exception, Feb 29, possibly an
 exception, and possibly/finally Feb 28th.  This makes pretty intuitive
 sense to most folks and is usually what's meant.

Well, yes, but that's just one way to solve the problem. I guess
I'll just add all possible solutions and then let the user decide
what's best in some way.

 I've found that issues and confusion stem more from the non-commutative
 reality that Jan 31 + (1 month) + (-1 month) != Jan 31 + (-1 month) +
 (1 month) or the non-associative Jan 31 + (1 month + 1 month) != (Jan
 31 + 1 month) + 1 month :-/

That's why mxDateTime actually returning a day in March...

 mx.DateTime.DateTime(2009, 1, 31) + mx.DateTime.RelativeDateTime(months=+1)
mx.DateTime.DateTime object for '2009-03-03 00:00:00.00' at 2ba43f93ebe0

That's intuitive for mathematicians only, though ;-)

 So yes, messy it is!

Indeed.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 12 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

2009-10-12 Thread M.-A. Lemburg
Rhodri James wrote:
 On Fri, 09 Oct 2009 13:39:43 +0100, Tim Chase
 python.l...@tim.thechases.com wrote:
 
 Month arithmetic is a bit of a mess, since it's not clear how
 to map e.g. Jan 31 + one month.

 Jan 31 + one month usually means add one to the month value and
 then keep backing off the day if you get an exception making the
 date, so you'd get Feb 31, exception, Feb 30, exception, Feb 29,
 possibly an exception, and possibly/finally Feb 28th.  This makes
 pretty intuitive sense to most folks and is usually what's meant.

 I've found that issues and confusion stem more from the
 non-commutative reality that Jan 31 + (1 month) + (-1 month) != Jan
 31 + (-1 month) + (1 month) or the non-associative Jan 31 + (1 month
 + 1 month) != (Jan 31 + 1 month) + 1 month :-/
 
 I'd hazard a guess that what we're actually seeing is people mentally
 rebasing their indices, i.e. counting from the end of the month rather
 than the start, which makes the last day of January and January 31
 not the same thing really.  Unfortunately we're very fuzzy about when
 we do things like this, which makes it hard on a poor programmer.

Ah, for that we have RelativeDateTime:

 # next month, last day of the month
 mx.DateTime.DateTime(2009, 1, 31) + mx.DateTime.RelativeDateTime(months=+1, 
 day=-1)
mx.DateTime.DateTime object for '2009-02-28 00:00:00.00' at 2ba43f95c088

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 12 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

2009-10-12 Thread M.-A. Lemburg
Chris Rebert wrote:
 On Mon, Oct 12, 2009 at 4:27 AM, Piet van Oostrum p...@cs.uu.nl wrote:
 greg g...@cosc.canterbury.ac.nz (g) wrote:

 g MRAB wrote:
 And when someone says January 30, do they really mean the day before
 the last day of the month?

 g No, no, that's January -2, a *completely* different thing!

 But for someone else it would be February -2.
 
 And for still others, it's the last $DAYOFWEEK of the month, which
 just happened to fall on the 30th.

That's a little more complicated:

 mx.DateTime.DateTime(2009, 1, 31).day_of_week
5
 # which is a ...
 mx.DateTime.Weekday[mx.DateTime.DateTime(2009, 1, 31).day_of_week]
'Saturday'

Now:

 # next month, last Saturday
 mx.DateTime.DateTime(2009, 1, 31) + mx.DateTime.RelativeDateTime(months=+1, 
 day=1, weekday=(5, -1))
mx.DateTime.DateTime object for '2009-02-28 00:00:00.00' at 2ba43f93ebe0

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 12 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

2009-10-11 Thread Rhodri James
On Fri, 09 Oct 2009 13:39:43 +0100, Tim Chase  
python.l...@tim.thechases.com wrote:



Month arithmetic is a bit of a mess, since it's not clear how
to map e.g. Jan 31 + one month.


Jan 31 + one month usually means add one to the month value and then  
keep backing off the day if you get an exception making the date, so  
you'd get Feb 31, exception, Feb 30, exception, Feb 29, possibly an  
exception, and possibly/finally Feb 28th.  This makes pretty intuitive  
sense to most folks and is usually what's meant.


I've found that issues and confusion stem more from the non-commutative  
reality that Jan 31 + (1 month) + (-1 month) != Jan 31 + (-1 month) +  
(1 month) or the non-associative Jan 31 + (1 month + 1 month) != (Jan  
31 + 1 month) + 1 month :-/


I'd hazard a guess that what we're actually seeing is people mentally
rebasing their indices, i.e. counting from the end of the month rather
than the start, which makes the last day of January and January 31
not the same thing really.  Unfortunately we're very fuzzy about when
we do things like this, which makes it hard on a poor programmer.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

2009-10-11 Thread MRAB

Rhodri James wrote:
On Fri, 09 Oct 2009 13:39:43 +0100, Tim Chase 
python.l...@tim.thechases.com wrote:



Month arithmetic is a bit of a mess, since it's not clear how
to map e.g. Jan 31 + one month.


Jan 31 + one month usually means add one to the month value and 
then keep backing off the day if you get an exception making the 
date, so you'd get Feb 31, exception, Feb 30, exception, Feb 29, 
possibly an exception, and possibly/finally Feb 28th.  This makes 
pretty intuitive sense to most folks and is usually what's meant.


I've found that issues and confusion stem more from the 
non-commutative reality that Jan 31 + (1 month) + (-1 month) != Jan 
31 + (-1 month) + (1 month) or the non-associative Jan 31 + (1 month 
+ 1 month) != (Jan 31 + 1 month) + 1 month :-/


I'd hazard a guess that what we're actually seeing is people mentally
rebasing their indices, i.e. counting from the end of the month rather
than the start, which makes the last day of January and January 31
not the same thing really.  Unfortunately we're very fuzzy about when
we do things like this, which makes it hard on a poor programmer.


And when someone says January 30, do they really mean the day before
the last day of the month? Where would it end? :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: mxDateTime history (Re: mktime, how to handle dates before 01-01-1970 ?)

2009-10-09 Thread Tim Chase

Month arithmetic is a bit of a mess, since it's not clear how
to map e.g. Jan 31 + one month.


Jan 31 + one month usually means add one to the month value 
and then keep backing off the day if you get an exception making 
the date, so you'd get Feb 31, exception, Feb 30, exception, Feb 
29, possibly an exception, and possibly/finally Feb 28th.  This 
makes pretty intuitive sense to most folks and is usually what's 
meant.


I've found that issues and confusion stem more from the 
non-commutative reality that Jan 31 + (1 month) + (-1 month) != 
Jan 31 + (-1 month) + (1 month) or the non-associative Jan 31 + 
(1 month + 1 month) != (Jan 31 + 1 month) + 1 month :-/


So yes, messy it is!

-tkc



--
http://mail.python.org/mailman/listinfo/python-list