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