Loading ...
Sorry, an error occurred while loading the content.
 

Re: ISO 8601 Function in Perl?

Expand Messages
  • Aron Roberts
    In the message ISO 8601 Function in Perl? , dated 2003-08-04, Prof. ... Jukka Yukka Korpela s terrific Web page on ISO 8601 provides sample code in various
    Message 1 of 4 , Aug 5, 2003
      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/time
      >functions (e.g., localtime(), timelocal(), etc.) which conform to
      >ISO 8601.

      Jukka "Yukka" Korpela's terrific Web page on ISO 8601 provides
      sample code in various languages, including Perl:

      "Info on ISO 8601, the date and time representation standard"
      http://www.cs.tut.fi/~jkorpela/iso8601.html

      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) =
      > gmtime(time);
      >$t = sprintf "%4d-%02d-%02dT%02d:%02dZ\n",
      > 1900+$year,$mon+1,$mday,$hour,$min;
      >print $t;

      If you wish to work with the local time, rather than UTC, you can likely:

      - Substitute localtime() for gmtime().

      - Remove the trailing "Z" from the end of the string
      following "sprintf".

      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:

      Dave Rolsky
      "The Many Dates and Times of Perl"
      O'Reilly Perl.com, March 13, 2003
      http://www.perl.com/pub/a/2003/03/13/datetime.html

      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
      libraries at:

      http://archive.develooper.com/datetime@.../

      (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
    • Sunatori, Go Simon
      ... In order to generate a Monthly Calendar, I need to extract the day of the week. I looked around and found function time2iso() in the help documentation.
      Message 2 of 4 , Aug 8, 2003
        Mike Morris 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..

        Aron Roberts wrote:
        >
        > Here's Jukka's example code in Perl "for getting the current date
        > and time and writing it in UTC":

        In order to generate a Monthly Calendar, I need to extract the day of
        the week. I looked around and found function time2iso() in the help
        documentation. However, it does not work in MacPerl 5.6.

        use HTTP::Date;
        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().

        use Time::Local;
        my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
        localtime(timelocal(0,0,0,1,($MM-1),($YYYY)));
        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>
      Your message has been successfully submitted and would be delivered to recipients shortly.