Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.7 KiB

  1. ;# ctime.pl is a simple Perl emulation for the well known ctime(3C) function.
  2. ;#
  3. ;# Waldemar Kebsch, Federal Republic of Germany, November 1988
  4. ;# [email protected]
  5. ;# Modified March 1990, Feb 1991 to properly handle timezones
  6. ;# $RCSfile: ctime.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:23:47 $
  7. ;# Marion Hakanson ([email protected])
  8. ;# Oregon Graduate Institute of Science and Technology
  9. ;#
  10. ;# usage:
  11. ;#
  12. ;# #include <ctime.pl> # see the -P and -I option in perl.man
  13. ;# $Date = &ctime(time);
  14. CONFIG: {
  15. package ctime;
  16. @DoW = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  17. @MoY = ('Jan','Feb','Mar','Apr','May','Jun',
  18. 'Jul','Aug','Sep','Oct','Nov','Dec');
  19. }
  20. sub ctime {
  21. package ctime;
  22. local($time) = @_;
  23. local($[) = 0;
  24. local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
  25. # Determine what time zone is in effect.
  26. # Use GMT if TZ is defined as null, local time if TZ undefined.
  27. # There's no portable way to find the system default timezone.
  28. $TZ = defined($ENV{'TZ'}) ? ( $ENV{'TZ'} ? $ENV{'TZ'} : 'GMT' ) : '';
  29. ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
  30. ($TZ eq 'GMT') ? gmtime($time) : localtime($time);
  31. # Hack to deal with 'PST8PDT' format of TZ
  32. # Note that this can't deal with all the esoteric forms, but it
  33. # does recognize the most common: [:]STDoff[DST[off][,rule]]
  34. if($TZ=~/^([^:\d+\-,]{3,})([+-]?\d{1,2}(:\d{1,2}){0,2})([^\d+\-,]{3,})?/){
  35. $TZ = $isdst ? $4 : $1;
  36. }
  37. $TZ .= ' ' unless $TZ eq '';
  38. $year += 1900;
  39. sprintf("%s %s %2d %2d:%02d:%02d %s%4d\n",
  40. $DoW[$wday], $MoY[$mon], $mday, $hour, $min, $sec, $TZ, $year);
  41. }
  42. 1;