File Coverage

blib/lib/LibWeb/Time.pm
Criterion Covered Total %
statement 22 23 95.6
branch 6 12 50.0
condition 1 3 33.3
subroutine 8 9 88.8
pod 0 6 0.0
total 37 53 69.8


line stmt bran cond sub pod time code
1             #==============================================================================
2             # LibWeb::Time -- Various time formats for libweb applications
3              
4             package LibWeb::Time;
5              
6             # Copyright (C) 2000 Colin Kong
7             #
8             # This program is free software; you can redistribute it and/or
9             # modify it under the terms of the GNU General Public License
10             # as published by the Free Software Foundation; either version 2
11             # of the License, or (at your option) any later version.
12             #
13             # This program is distributed in the hope that it will be useful,
14             # but WITHOUT ANY WARRANTY; without even the implied warranty of
15             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16             # GNU General Public License for more details.
17             #
18             # You should have received a copy of the GNU General Public License
19             # along with this program; if not, write to the Free Software
20             # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21             #=============================================================================
22              
23             # $Id: Time.pm,v 1.4 2000/07/19 20:31:57 ckyc Exp $
24              
25             $VERSION = '0.02';
26              
27             #-##########################
28             # Use standard library.
29 1     1   1069 use strict;
  1         2  
  1         46  
30 1     1   8 use vars qw($VERSION);
  1         2  
  1         534  
31              
32             #-##########################
33             # Methods.
34             sub new {
35 1     1 0 68 my($class, $self);
36 1         3 $class = shift;
37              
38 1         161 my($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime();
39 1         4 my $month = $mon + 1;
40 1         1 my $month_day = $mday;
41 1 50       18 $self = {
    50          
    50          
    50          
    50          
    50          
42             'sec' => ($sec < 10) ? "0$sec" : $sec,
43             'min' => ($min < 10) ? "0$min" : $min,
44             'hour' => ($hour < 10) ? "0$hour" : $hour,
45             'mday' => ($mday < 10) ? "0$mday" : $mday,
46             'month' => ($month < 10) ? "0$month" : $month,
47             'month_day' => ($month_day < 10) ? "0$month_day" : $month_day,
48             'mon' => ('Jan','Feb','March','April','May','June','July','Aug','Sep','Oct','Nov','Dec')[$mon],
49             'year' => $year + 1900,
50             'wday' => ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$wday]
51             };
52 1   33     12 bless( $self, ref($class) || $class );
53             }
54              
55 0     0   0 sub DESTROY {}
56              
57             sub get_date {
58             # return 'wday month mday'.
59 1     1 0 38 my $self = shift;
60 1         12 $self->{wday}.' '.$self->{mon}.' '.$self->{mday};
61             }
62              
63             sub get_time {
64             # return hh:mm:ss
65 1     1 0 2 my $self = shift;
66 1         4 $self->{hour}.':'.$self->{min}.':'.$self->{sec};
67             }
68              
69             sub get_datetime {
70             # return 'wday mm dd hh:mm:ss yyyy'.
71 1     1 0 2 my $self = shift;
72 1         6 $self->{wday}.' '.$self->{mon}.' '.$self->{mday}.' '.
73             $self->{hour}.':'.$self->{min}.':'.$self->{sec}.' '.$self->{year};
74             }
75              
76             sub get_timestamp {
77             # return 'yyyymmddhhmmss'.
78 1     1 0 2 my $self = shift;
79 1         6 $self->{year}.$self->{month}.$self->{month_day}.$self->{hour}.$self->{min}.$self->{sec};
80             }
81              
82             sub get_year {
83             # return 'yyyy'.
84 1     1 0 3 shift->{'year'};
85             }
86              
87             1;
88             __END__