Re: ISO 8601 Function in Perl?
- In the message "ISO 8601 Function in Perl?", dated 2003-08-04, Prof.
Simon Sunatori wrote:
>I am wondering if there are any pre-written [Perl] date/timeJukka "Yukka" Korpela's terrific Web page on ISO 8601 provides
>functions (e.g., localtime(), timelocal(), etc.) which conform to
sample code in various languages, including Perl:
"Info on ISO 8601, the date and time representation standard"
Here's Jukka's example code in Perl "for getting the current date
and time and writing it in UTC":
>($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =If you wish to work with the local time, rather than UTC, you can likely:
>$t = sprintf "%4d-%02d-%02dT%02d:%02dZ\n",
- Substitute localtime() for gmtime().
- Remove the trailing "Z" from the end of the string
To generate an unambiguous representation of the local time, you
would need to also add an ISO 8601-confirming representation of the
local offset from UTC to the end of the time string.
If you wish to learn more about the built-in functions and various
add-on modules (libraries) available for working with dates and times
in Perl -- some of the latter quite extensive in their functionality
-- the following article is a great starting place:
"The Many Dates and Times of Perl"
O'Reilly Perl.com, March 13, 2003
Near the end of this article, Dave also mentions his own suite of
date and time modules, which are ultimately intended to be
comprehensive. You can view archives of the discussions about these
(The hostname "develooper" above is spelled correctly :-)
Aron Roberts Workstation Software Support Group . 221 Evans Hall
University of California, Berkeley, CA 94720-3808 USA
aron@... . +1 510-642-5974 . fax 510-643-5385
- Mike Morris wrote:
>Aron Roberts wrote:
> See http://datetime.perl.org/modules.html.
> If there's such a thing, I'd expect it to be there.
> There is a "DateTime::Format::ISO8601" Modules that "Parses ISO8601
> formats", but not sure about the other way..
>In order to generate a Monthly Calendar, I need to extract the day of
> Here's Jukka's example code in Perl "for getting the current date
> and time and writing it in UTC":
the week. I looked around and found function time2iso() in the help
documentation. However, it does not work in MacPerl 5.6.
print time2iso(time),"\n"; # outputs:
# Undefined subroutine &main::time2iso called.
There is no module "DateTime::Format::ISO8601" in MacPerl 5.6, either.
Therefore, I picked function timelocal() and used Jukka's example
code. With this, I do not need function POSIX::strftime().
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
print sprintf("%4d-%02d-%02dT%02d:%02d:%02d,0", ($year + 1900),
($mon + 1), $mday, $hour, $min, $sec);
It has come to my attention that element "$wday" from PERL function
localtime() supports only years from 1954 to 2039, while AppleScript
function "date" supports the full Gregorian Calendar from 1582 to 3999.
* AppleScript | http://WWW.HyperInfo.CA/~HyperInfo.CA/Calendar.html
* PERL | http://WWW.HyperInfo.CA/~HyperInfo.CA/Calendarr.html
The problem does not appear to be platform-specific or
version-specific. I hope that "The Perl DateTime Project" will
address the localtime() issue...
Thank you very much for your attention.
Merci de votre attention.
Prof. Simon Sunatori, P.Eng./ing., M.Eng. (Engineering Physics), F.N.A.
President & Chief Executive Officer
HyperInfo Canada Inc.
Simon Sunatori <http://WWW.HyperInfo.CA/~GS.Sunatori@.../>
65, des Parulines <mailto:GS.Sunatori@...>
Gatineau (Quebec) <telephone:+1-819-595-9210>
CANADA J9A 1Z4 <facsimile:+1-425-984-7292>