Heiko Klein schreef:
> The DateTime module allows handling of a large range of dates, much 
> larger than the standard unix epoch (from ~1901 to ~2038). This is 
> really nice. But when calling the DateTime->from_epoch(epoch => 2**31) 
> gives not 2038 as I hoped for, but 1901 due to an internal call to gmtime.

Hi Heiko,

You may want to take a look at DateTime::Format::Epoch::Unix. It does not use
gmtime internally, and may therefore be slower than the from_epoch() method,
but it does return the correct results for the years you are interested in:

    use DateTime;
    use DateTime::Format::Epoch::Unix;

    $dt = DateTime::Format::Epoch::Unix->parse_datetime(1e10);
    print "$dt\n"

    # output: 2286-11-20T17:46:40

If you work with even larger numbers, you can make DateTime::Format:Epoch use
Math::BigInt, but that is not necessary in your case.

> Wouldn't it be possible to implement this directly into the from_epoch 
> routine. Caveats would be missing leap-seconds before 1901 and after 
> 2038. (Any more?) But at least dates up to year 5million would be possible.

At least in Unix, leap seconds are not counted, so that is not a problem in
your workaround.

Eugene

Reply via email to