Re: [Zope-dev] Re: Changing DateTime to use pytz

2007-10-05 Thread Lennart Regebro
On 10/5/07, Laurence Rowe [EMAIL PROTECTED] wrote:
 I've tested my patch (datetime.datetime support) against Amos's branch
 and it applies cleanly and all tests pass.

Cool! Are there tests to make sure old pickles still work, or do we
know that this is the case for sure?

-- 
Lennart Regebro: Zope and Plone consulting.
http://www.colliberty.com/
+33 661 58 14 64
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Re: Changing DateTime to use pytz

2007-10-05 Thread Laurence Rowe

Lennart Regebro wrote:

On 10/5/07, Laurence Rowe [EMAIL PROTECTED] wrote:

I've tested my patch (datetime.datetime support) against Amos's branch
and it applies cleanly and all tests pass.


Cool! Are there tests to make sure old pickles still work, or do we
know that this is the case for sure?



My patch updates the existing test (substituting _millis for _micros):

def testUpgradeOldInstances(self):
# Compare dates that don't have the _micros attribute yet
dt = DateTime('1997/1/1')
dt1 = DateTime('1997/2/2')
del dt._micros
del dt1._micros
self.testCompareOperations(dt, dt1)

If anyone thinks it is important I could an explicit upgrade path for 
instances with a _millis attribute too (most current instances I would 
assume). _upgrade_old should work fine for them too as they have a time 
float _t attribute.


def _upgrade_old(self):
Upgrades a previously pickled DateTime object.
micros = long(math.floor(self._t * 100.0))
self._micros = micros
return micros

Laurence

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Re: Changing DateTime to use pytz

2007-10-05 Thread Laurence Rowe
I've tested my patch (datetime.datetime support) against Amos's branch 
and it applies cleanly and all tests pass.


It seems though that the new timezones are not used much... doing a 
DateTime() gives me DateTime('2007/10/05 14:20:27.204176 GMT+1') (with 
my pathc applied too). Looking up tz = d._tzinfo[d.timezone()] gives me 
an old style timezone, as _tz is 'GMT+1'.


It would be very useful to be able to get pytz tzinfo for a DateTime 
object. It would allow me to return a timezone aware datetime.datetime 
from asdatetime().


Ideally the old names should be mapped onto pytz timezones.

Laurence

Laurence Rowe wrote:
I've been working on this too today (well datetime handling anyway). 
Please see my patch at https://bugs.launchpad.net/zope2/+bug/149060


Laurence


Amos Latteier wrote:

Hi,

I wanted to let folks know that I've created the amos-datetime-pytz
branch with my changes.

Please let me know when/if you'd like me to merge this to the trunk.

Of course I'm also happy to receive any criticism or comments on the 
changes.


Thanks!

-Amos
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -  http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )



___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )



___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Re: Changing DateTime to use pytz

2007-10-05 Thread Amos Latteier
On 10/5/07, Laurence Rowe [EMAIL PROTECTED] wrote:
 It seems though that the new timezones are not used much... doing a
 DateTime() gives me DateTime('2007/10/05 14:20:27.204176 GMT+1') (with
 my pathc applied too). Looking up tz = d._tzinfo[d.timezone()] gives me
 an old style timezone, as _tz is 'GMT+1'.

If a the timezone has a name that pytz understands then it uses pytz.
Otherwise it falls back on DateTime's timezone database. The most
common example of when pytz won't be used is with fixed offset
timezones like GMT+1. pytz.common_timezones doesn't doesn't contain
time zones like this. Anyway DateTime handles fixed offset time zones
just fine since there's no daylight savings to deal with.

 It would be very useful to be able to get pytz tzinfo for a DateTime
 object. It would allow me to return a timezone aware datetime.datetime
 from asdatetime().

DateTime instances only store the name of their timezone, not the
timezone object. So when converting to a datetime object I suggest
that you generate a tzinfo object yourself. This shouldn't be too hard
since DateTime is willing to give you a timezone that provides a name,
dst flag, and offset from UTC. See _timezone.info()

 Ideally the old names should be mapped onto pytz timezones.

Names that pytz understands use pytz time zone info, regardless of
when the DateTime instance was created. Or maybe you are asking
something else.

Also DateTime supports some abbreviations. For example, 'est' is
mapped to 'US/Eastern'. So old instances that use 'est' as a time zone
should work with pytz. There are probably improvements that can be
made here, but I didn't bother since my goal was to change as little
as possible.

-Amos
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Re: Changing DateTime to use pytz

2007-10-05 Thread Lennart Regebro
On 10/5/07, Laurence Rowe [EMAIL PROTECTED] wrote:
 If anyone thinks it is important I could an explicit upgrade path for
 instances with a _millis attribute too (most current instances I would
 assume).

I think the code must work with current instances without modifying them.

-- 
Lennart Regebro: Zope and Plone consulting.
http://www.colliberty.com/
+33 661 58 14 64
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Re: Changing DateTime to use pytz

2007-10-05 Thread Laurence Rowe

Lennart Regebro wrote:


On 10/5/07, Laurence Rowe [EMAIL PROTECTED] wrote:

If anyone thinks it is important I could an explicit upgrade path for
instances with a _millis attribute too (most current instances I would
assume).


I think the code must work with current instances without modifying them.



All the tests still pass if I comment out the assignment:

def _upgrade_old(self):
Upgrades a previously pickled DateTime object.
micros = long(math.floor(self._t * 100.0))
#self._micros = micros # don't upgrade instances in place
return micros

New patch at http://launchpadlibrarian.net/9811478/DateTime.patch

Laurence

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Re: Changing DateTime to use pytz

2007-10-05 Thread Lennart Regebro
On 10/5/07, Laurence Rowe [EMAIL PROTECTED] wrote:
 All the tests still pass if I comment out the assignment:

  def _upgrade_old(self):
  Upgrades a previously pickled DateTime object.
  micros = long(math.floor(self._t * 100.0))
  #self._micros = micros # don't upgrade instances in place
  return micros

That seems like a reasonable solution. (Although maybe _upgrade_old
isn't the best method name then, but that's details ;) ),

-- 
Lennart Regebro: Zope and Plone consulting.
http://www.colliberty.com/
+33 661 58 14 64
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Re: Changing DateTime to use pytz

2007-10-04 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Amos Latteier wrote:
 Andreas Jung wrote:
 I would not care much about dropping the support for weird timezone names
 without further notice  as long as their is an easy way for people
 migrating their code e.g. by specifying a proper tz name.
 
 I should clarify that they are mostly abbreviations.
 
 I also agree with Lennart Regebro, that the correct solution is to
 replace DateTime with datetime, and so it's not worth breaking too
 much.

I think consensus here is that the DateTIme stuff has BBB contracts
which are literally unbreakable:

 - millions of pickles are out there in ZODB land which will barf if
   DateTime doesn't preserve existing semantics.

 - Bunches of third-party application code uses the DateTime API, in
   particular the DWIMish constructor.

I think your change (using pytz to handle timezones, with fallback to
the older code) is a sensible compromise.


Tres.
- --
===
Tres Seaver  +1 540-429-0999  [EMAIL PROTECTED]
Palladion Software   Excellence by Designhttp://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHBSXU+gerLs4ltQ4RAp0hAJ9YAKnuSkYGBMLG9zEK/qoLv6VMHwCfbXgJ
XkIPQNsmCgRHRlmExFhMk9E=
=ki/q
-END PGP SIGNATURE-
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Re: Changing DateTime to use pytz

2007-10-04 Thread Laurence Rowe
I've been working on this too today (well datetime handling anyway). 
Please see my patch at https://bugs.launchpad.net/zope2/+bug/149060


Laurence


Amos Latteier wrote:

Hi,

I wanted to let folks know that I've created the amos-datetime-pytz
branch with my changes.

Please let me know when/if you'd like me to merge this to the trunk.

Of course I'm also happy to receive any criticism or comments on the changes.

Thanks!

-Amos
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce

 http://mail.zope.org/mailman/listinfo/zope )



___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope )