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.

84 lines
2.3 KiB

  1. package Time::localtime;
  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(localtime ctime);
  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 localtime (;$) { populate CORE::localtime(@_ ? shift : time)}
  29. sub ctime (;$) { scalar CORE::localtime(@_ ? shift : time) }
  30. 1;
  31. __END__
  32. =head1 NAME
  33. Time::localtime - by-name interface to Perl's built-in localtime() function
  34. =head1 SYNOPSIS
  35. use Time::localtime;
  36. printf "Year is %d\n", localtime->year() + 1900;
  37. $now = ctime();
  38. use Time::localtime;
  39. use File::stat;
  40. $date_string = ctime(stat($file)->mtime);
  41. =head1 DESCRIPTION
  42. This module's default exports override the core localtime() function,
  43. replacing it with a version that returns "Time::tm" objects.
  44. This object has methods that return the similarly named structure field
  45. name from the C's tm structure from F<time.h>; namely sec, min, hour,
  46. mday, mon, year, wday, yday, and isdst.
  47. You may also import all the structure fields directly into your namespace
  48. as regular variables using the :FIELDS import tag. (Note that this still
  49. overrides your core functions.) Access these fields as
  50. variables named with a preceding C<tm_> in front their method names.
  51. Thus, C<$tm_obj-E<gt>mday()> corresponds to $tm_mday if you import
  52. the fields.
  53. The ctime() function provides a way of getting at the
  54. scalar sense of the original CORE::localtime() function.
  55. To access this functionality without the core overrides,
  56. pass the C<use> an empty import list, and then access
  57. function functions with their full qualified names.
  58. On the other hand, the built-ins are still available
  59. via the C<CORE::> pseudo-package.
  60. =head1 NOTE
  61. While this class is currently implemented using the Class::Struct
  62. module to build a struct-like class, you shouldn't rely upon this.
  63. =head1 AUTHOR
  64. Tom Christiansen