Ticket #390 (closed defect: fixed)

Opened 15 months ago

Last modified 14 months ago

encoding/decoding dates prior to 1970 with Windows

Reported by: arman0 Owned by: nick
Priority: major Milestone: 0.4
Component: Decoder Version: 0.3.1
Keywords: Cc:
Fixed in revision: Branch:
Author:

Description (last modified by thijs) (diff)

The following example results in an exception:

from pyamf import amf3, util
from datetime import date

buf = util.BufferedByteStream()
encoder = amf3.Encoder(buf, context=amf3.Context())
encoder.writeElement(date(1969, 1, 1))

t = buf.getvalue()
x = amf3.Decoder(t)
x.readElement()

Change History

  Changed 15 months ago by thijs

  • milestone set to 0.4

When I run your script with the trunk version of PyAMF (r1852) and print x it returns:

<pyamf.amf3.Decoder object at 0x642910>

so it seems to be fixed on the trunk? Can you give that a try? I haven't tested it with the 0.3.1 release but there could definitely be something wrong in that version.

  Changed 15 months ago by nick

  • owner changed from nick to arman0
  • status changed from new to assigned

I've tested that snippet all the way back to PyAMF 0.1b and they all work, which version are you using?

import pyamf

print pyamf.__version__

  Changed 15 months ago by nick

  • milestone 0.4 deleted

  Changed 15 months ago by arman0

I'm using version 3.1. However, the problem appears to be with Windows. On Linux, this works fine.

On Linux:

>>> import datetime
>>> datetime.datetime.utcfromtimestamp(-31536000.0)
datetime.datetime(1969, 1, 1, 0, 0)

On Windows with python 2.5/2.6/3.0:

>>> import datetime
>>> datetime.datetime.utcfromtimestamp(-31536000.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: timestamp out of range for platform localtime()/gmtime() function

See  issue2494.

  Changed 15 months ago by thijs

  • summary changed from encoding/decoding dates prior to 1970 to encoding/decoding dates prior to 1970 with Windows
  • description modified (diff)
  • milestone set to 0.5

If we don't take timezone in consideration, which we don't afaik, then this workaround (from  issue2494) should work on all platforms:

>>> datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=-86400)
datetime.datetime(1969, 12, 31, 0, 0)

  Changed 15 months ago by thijs

  • owner changed from arman0 to nick

follow-up: ↓ 10   Changed 14 months ago by nick

  • keywords review added
  • owner changed from nick to thijs

echo test and slaves look good.

  Changed 14 months ago by thijs

  • status changed from assigned to accepted
  • milestone changed from 0.5 to 0.4

  Changed 14 months ago by nick

in reply to: ↑ 7   Changed 14 months ago by thijs

  • keywords review removed
  • owner changed from thijs to nick
  • status changed from accepted to assigned

Replying to nick:

echo test and slaves look good.

In that case merge.

  Changed 14 months ago by nick

  • status changed from assigned to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.