This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix diagnostics to report "our" vs "my" correctly
[perl5.git] / lib / Time / gmtime.pm
CommitLineData
36477c24 1package Time::gmtime;
2use strict;
3use Time::tm;
4
5BEGIN {
6 use Exporter ();
03136e13 7 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
36477c24 8 @ISA = qw(Exporter Time::tm);
9 @EXPORT = qw(gmtime gmctime);
10 @EXPORT_OK = qw(
11 $tm_sec $tm_min $tm_hour $tm_mday
12 $tm_mon $tm_year $tm_wday $tm_yday
13 $tm_isdst
14 );
15 %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
03136e13 16 $VERSION = 1.01;
36477c24 17}
18use vars @EXPORT_OK;
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
03136e13
CS
31sub gmtime (;$) { populate CORE::gmtime(@_ ? shift : time)}
32sub gmctime (;$) { scalar CORE::gmtime(@_ ? shift : time)}
36477c24 33
341;
35__END__
36
37=head1 NAME
38
2ae324a7 39Time::gmtime - by-name interface to Perl's built-in gmtime() function
36477c24 40
41=head1 SYNOPSIS
42
43 use Time::gmtime;
44 $gm = gmtime();
45 printf "The day in Greenwich is %s\n",
46 (qw(Sun Mon Tue Wed Thu Fri Sat Sun))[ gm->wday() ];
47
48 use Time::gmtime w(:FIELDS;
49 printf "The day in Greenwich is %s\n",
50 (qw(Sun Mon Tue Wed Thu Fri Sat Sun))[ gm_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
ae83f377 72The gmctime() function provides a way of getting at the
36477c24 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
8cc95fdb 83While this class is currently implemented using the Class::Struct
36477c24 84module to build a struct-like class, you shouldn't rely upon this.
85
86=head1 AUTHOR
87
88Tom Christiansen