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