This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
$VERSION crusade, strict, tests, etc... all over lib/
[perl5.git] / lib / Time / localtime.pm
CommitLineData
36477c24 1package Time::localtime;
2use strict;
3use Time::tm;
4
17f410f9
GS
5use 5.005_64;
6our(@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
7BEGIN {
36477c24 8 use Exporter ();
36477c24 9 @ISA = qw(Exporter Time::tm);
10 @EXPORT = qw(localtime ctime);
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 ] );
03136e13 17 $VERSION = 1.01;
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
CS
32sub localtime (;$) { populate CORE::localtime(@_ ? shift : time)}
33sub ctime (;$) { scalar CORE::localtime(@_ ? shift : time) }
36477c24 34
351;
36
37__END__
38
39=head1 NAME
40
2ae324a7 41Time::localtime - by-name interface to Perl's built-in localtime() function
36477c24 42
43=head1 SYNOPSIS
44
45 use Time::localtime;
46 printf "Year is %d\n", localtime->year() + 1900;
47
48 $now = ctime();
49
50 use Time::localtime;
51 use File::stat;
52 $date_string = ctime(stat($file)->mtime);
53
54=head1 DESCRIPTION
55
56This module's default exports override the core localtime() function,
57replacing it with a version that returns "Time::tm" objects.
58This object has methods that return the similarly named structure field
59name from the C's tm structure from F<time.h>; namely sec, min, hour,
60mday, mon, year, wday, yday, and isdst.
61
62You may also import all the structure fields directly into your namespace
63as regular variables using the :FIELDS import tag. (Note that this still
64overrides your core functions.) Access these fields as
65variables named with a preceding C<tm_> in front their method names.
66Thus, C<$tm_obj-E<gt>mday()> corresponds to $tm_mday if you import
67the fields.
68
ae83f377 69The ctime() function provides a way of getting at the
36477c24 70scalar sense of the original CORE::localtime() function.
71
72To access this functionality without the core overrides,
73pass the C<use> an empty import list, and then access
74function functions with their full qualified names.
75On the other hand, the built-ins are still available
76via the C<CORE::> pseudo-package.
77
78=head1 NOTE
79
8cc95fdb 80While this class is currently implemented using the Class::Struct
36477c24 81module to build a struct-like class, you shouldn't rely upon this.
82
83=head1 AUTHOR
84
85Tom Christiansen