home *** CD-ROM | disk | FTP | other *** search
- README file for the ptime.pl perl library
- =========================================
- Author: Jeff Kellem <composer@chem.bu.edu>
- Last Date Modified: 21 Feb 1991
- Version: 0.8a (first release)
-
- [ Note: This was quickly thrown together to provide some docs. Just
- look at the code for now.. ;-) ]
-
- This is the ptime.pl library, a way of formatting date/time info inside
- perl programs. The formatting characters were based on the versions of
- the unix date command that support +FORMAT for outputting the date in a
- user-specified format.
-
- A friend of mine wanted something that would accept the date +FORMAT
- formatting characters to output the current date/time; an OS upgrade
- replaced a version of date that used the +FORMAT stuff with one that
- didn't. That's how this started...
-
- There's a quick replacement of the date command supporting the +FORMAT
- stuff included. Look in ./date for where to set a default timezone to
- use if the TZ environment variable is not set. It's currently set to
- EST5EDT; that's the zone I live in. :) The `-u' switch to date will
- display in GMT. You can change the format to display the date/time in
- via the '+FORMAT' switch, where FORMAT is made up of %-escape sequences
- that the &'ptime routine described below accepts. [Also, look at the
- ptime.pl source.] I'll include a man page (wrapped around date) in a
- following release.
-
- The special format %-escape sequences are:
- ESCAPE REPLACED BY
- %n newline
- %t tab
- %a abbreviated weekday name (Sun to Sat)
- %A full weekday name
- %b abbrev. month name (Jan to Dec)
- %h abbrev. month name (Jan to Dec)
- %B full month name
- %d day of month (01 to 31)
- %e day of month ( 1 to 31) [single digits preceded by a space]
- %m month (01 to 12)
- %D mm/dd/yy
- %H hour (00 to 23)
- %I hour (01 to 12)
- %M minutes (00 to 59)
- %S seconds (00 to 59)
- %p AM or PM
- %j day of year (001 to 366)
- %w day of week (Sunday == 0)
- %r hh:mm:ss [AP]M
- %R hh:mm
- %T hh:mm:ss
- %y year (last 2 digits)
- %Y year (4 digits, 19xx, 20xx)
- %Z timezone
- %% a single `%'
-
- The user accessible routines in the ptime.pl perl library are:
-
- &'ptime($format, $time);
- &'zonetime($time);
- &'ctime($time);
-
- &'ptime($format, $time);
- &'ptime('', $time);
- &'ptime($format);
- &'ptime;
-
- Returns the date/time specified via $time in number of seconds from the
- "beginning of time" formatted as specified by $format. If $format is
- null or not specified, $ptime'default_format ('%a %h %d %T %Z %Y') is
- used. This is the same as the ctime(3) format minus the newline. If
- $time is not specified, the current time is used. N.B.: If $time is
- null, the "beginning of time" (0 seconds) is used. $format may contain
- the %-escape characters mentioned above.
-
- Examples:
- print &'ptime("%D %T %Z\n",time); # prints "02/17/91 14:23:54 GMT\n"
- $date = &'ptime('%d %h %Y',time); # $date = "17 Feb 1991";
- $filename = &'ptime('%d_%h_%Y'); # $filename = "17_Feb_1991";
-
- $ptime'default_TZ specifies a timezone to use if the TZ environment
- variable is not set. By default, this is set to 'GMT'. If you're in
- EST, you can set it to 'EST5EDT' so that localtime is used, for
- example.
-
- &'zonetime($time);
- &'zonetime;
-
- Basically, a wrapper around gmtime/localtime. It returns the same LIST
- as gmtime/localtime do. Which function is used depends on the TZ
- environment variable, if set. If TZ is not set, $ptime'default_TZ is
- used instead. If $time is not specified, the current time is used.
-
- &'ctime($time);
- &'ctime;
-
- Returns a string similar to the ctime(3) function. It's the same as
- the format "%a %h %d %T %Z %Y\n". If $time is not specified, the
- current time is used.
-
- Limitations
- -----------
- * based on SysV date +FORMAT stuff ;-)
- * doesn't parse left to right (or at all), just replaces what it finds
- in the order specified in the code. So '%%y' would return '%91'..
- * biased towards American date formats
- * needs a couple more hooks for customization for other languages
- may add in the near future.
- * zonetime is probably an incorrect name, as you don't get back the time
- struct as broken down for the specified timezone. zonetime only
- determines whether to use gmtime or localtime.
- * if $time is 0 and timezone is "before" the GMT, the year will print out as
- 2069 instead of 1969. Oh well... ;-}
-
- Possible Future Enhancements
- ----------------------------
- * Complete support for other language formats for dates/times.
- * Is there really anything else one would want in date formatting
- routines? ;-}
- * Include subs for other languages, already have french and german, somewhat.
- * Other language time/date formats welcome.
- * If you have an idea that you might want included in here, let me know.
- My email address is at the top of the README and inside each source file.
-