| 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 | 1 | $VERSION = '0.02'; | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | #-########################## | ||||||||||||||||||||||||||||||
| 28 | # Use standard library. | ||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | #-########################## | ||||||||||||||||||||||||||||||
| 33 | # Methods. | ||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 35 | 1 | my($class, $self); | |||||||||||||||||||||||||||||
| 36 | 1 | $class = shift; | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | 1 | my($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(); | |||||||||||||||||||||||||||||
| 39 | 1 | my $month = $mon + 1; | |||||||||||||||||||||||||||||
| 40 | 1 | my $month_day = $mday; | |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | $self = { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 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 | ▶ | bless( $self, ref($class) || $class ); | ||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub DESTROY {} | ||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | sub get_date { | ||||||||||||||||||||||||||||
|
Subroutine
get_date: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 58 | # return 'wday month mday'. | ||||||||||||||||||||||||||||||
| 59 | 1 | my $self = shift; | |||||||||||||||||||||||||||||
| 60 | 1 | $self->{wday}.' '.$self->{mon}.' '.$self->{mday}; | |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub get_time { | ||||||||||||||||||||||||||||
|
Subroutine
get_time: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 64 | # return hh:mm:ss | ||||||||||||||||||||||||||||||
| 65 | 1 | my $self = shift; | |||||||||||||||||||||||||||||
| 66 | 1 | $self->{hour}.':'.$self->{min}.':'.$self->{sec}; | |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub get_datetime { | ||||||||||||||||||||||||||||
|
Subroutine
get_datetime: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 70 | # return 'wday mm dd hh:mm:ss yyyy'. | ||||||||||||||||||||||||||||||
| 71 | 1 | my $self = shift; | |||||||||||||||||||||||||||||
| 72 | $self->{wday}.' '.$self->{mon}.' '.$self->{mday}.' '. | ||||||||||||||||||||||||||||||
| 73 | 1 | $self->{hour}.':'.$self->{min}.':'.$self->{sec}.' '.$self->{year}; | |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub get_timestamp { | ||||||||||||||||||||||||||||
|
Subroutine
get_timestamp: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 77 | # return 'yyyymmddhhmmss'. | ||||||||||||||||||||||||||||||
| 78 | 1 | my $self = shift; | |||||||||||||||||||||||||||||
| 79 | 1 | $self->{year}.$self->{month}.$self->{month_day}.$self->{hour}.$self->{min}.$self->{sec}; | |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | sub get_year { | ||||||||||||||||||||||||||||
|
Subroutine
get_year: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 83 | # return 'yyyy'. | ||||||||||||||||||||||||||||||
| 84 | 1 | shift->{'year'}; | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | 1 | 1; | |||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||||