develooper Front page | perl.perl6.language | Postings from May 2005

date and time formatting

Thread Next
Nathan Gray
May 31, 2005 06:44
date and time formatting
Message ID:
As I am interested in human-readable dates and times, and having found
no conclusive discussion on time formatting, I make my recommendation
for a syntax (to start discussion, and allow for date formatting to be
implemented in pugs):

I would like for time() to return an object, which in numeric context is
the number of seconds from the epoch (the new epoch, of course), and
which in string context is a human-readable string.  We could also use
localtime(), and leave time() alone.

Possible syntax could be:

  $time_object = time();
  $epoch_seconds = +$time_object;
  $human_readable = ~$time_object;
  $human_readable = $time_object.format; # default format
  $human_readable = $time_object.format($pattern);
  $human_readable = $time_object.format($pattern, offset => 'local');

The default offset would probably be 'local', and would account for
daylight saving time.  The offset could be changed to a 
floating-point value indicating hours offset from UTC.  A timezone
module could perhaps allow for timezone names, which would allow for
daylight saving time computation for non-local times.  The default
offset would probably be stored in a global variable.

The default format would probably be an ISO 8601 format, like:


and the default format pattern would probably be stored in a global
variable, possibly as an strftime() pattern.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About