Thank you, this is exactly what I've been looking for. But after putting
it into my programs, I realized a hard performance fallback.
My program handles usually a year of hourly data, comparing those to
other times etc. A benchmark (simply` creating dates) gave the answer,
DateTime seems to be to slow for my purpose: times for 1 year:
DateTime: 0.42/s
DateTime::Format::Epoch::Unix: 0.19/s
gmtime: 71/s
udunits: 35/s
The object-oriented way of handling times in perl seems to be about 100
slower than the functional oriented (udunits is a scientific C-Code with
simple perl bindings, handling dates similar to gmtime, but without
restriction to 2038). Too bad, I really like the ellegance of DateTime
date handling.
Best regards,
Heiko
Eugene van der Pijll wrote:
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
--
Dr. Heiko Klein Tel. + 47 22 96 33 44
Air pollution Section/Research Department Fax. + 47 22 69 63 55
Norwegian Meteorological Institute http://www.met.no
P.O. Box 43 Blindern 0313 Oslo NORWAY http://www.emep.int