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