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.

88 lines
2.5 KiB

  1. package Time::gmtime;
  2. use strict;
  3. use Time::tm;
  4. BEGIN {
  5. use Exporter ();
  6. use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
  7. @ISA = qw(Exporter Time::tm);
  8. @EXPORT = qw(gmtime gmctime);
  9. @EXPORT_OK = qw(
  10. $tm_sec $tm_min $tm_hour $tm_mday
  11. $tm_mon $tm_year $tm_wday $tm_yday
  12. $tm_isdst
  13. );
  14. %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
  15. $VERSION = 1.01;
  16. }
  17. use vars @EXPORT_OK;
  18. sub populate (@) {
  19. return unless @_;
  20. my $tmob = Time::tm->new();
  21. @$tmob = (
  22. $tm_sec, $tm_min, $tm_hour, $tm_mday,
  23. $tm_mon, $tm_year, $tm_wday, $tm_yday,
  24. $tm_isdst )
  25. = @_;
  26. return $tmob;
  27. }
  28. sub gmtime (;$) { populate CORE::gmtime(@_ ? shift : time)}
  29. sub gmctime (;$) { scalar CORE::gmtime(@_ ? shift : time)}
  30. 1;
  31. __END__
  32. =head1 NAME
  33. Time::gmtime - by-name interface to Perl's built-in gmtime() function
  34. =head1 SYNOPSIS
  35. use Time::gmtime;
  36. $gm = gmtime();
  37. printf "The day in Greenwich is %s\n",
  38. (qw(Sun Mon Tue Wed Thu Fri Sat Sun))[ gm->wday() ];
  39. use Time::gmtime w(:FIELDS;
  40. printf "The day in Greenwich is %s\n",
  41. (qw(Sun Mon Tue Wed Thu Fri Sat Sun))[ gm_wday() ];
  42. $now = gmctime();
  43. use Time::gmtime;
  44. use File::stat;
  45. $date_string = gmctime(stat($file)->mtime);
  46. =head1 DESCRIPTION
  47. This module's default exports override the core gmtime() function,
  48. replacing it with a version that returns "Time::tm" objects.
  49. This object has methods that return the similarly named structure field
  50. name from the C's tm structure from F<time.h>; namely sec, min, hour,
  51. mday, mon, year, wday, yday, and isdst.
  52. You may also import all the structure fields directly into your namespace
  53. as regular variables using the :FIELDS import tag. (Note that this
  54. still overrides your core functions.) Access these fields as variables
  55. named with a preceding C<tm_> in front their method names. Thus,
  56. C<$tm_obj-E<gt>mday()> corresponds to $tm_mday if you import the fields.
  57. The gmctime() function provides a way of getting at the
  58. scalar sense of the original CORE::gmtime() function.
  59. To access this functionality without the core overrides,
  60. pass the C<use> an empty import list, and then access
  61. function functions with their full qualified names.
  62. On the other hand, the built-ins are still available
  63. via the C<CORE::> pseudo-package.
  64. =head1 NOTE
  65. While this class is currently implemented using the Class::Struct
  66. module to build a struct-like class, you shouldn't rely upon this.
  67. =head1 AUTHOR
  68. Tom Christiansen