Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This software is Copyright (c) 2010-2017 by the AUTHORS.
This software is Copyright (c) 2010-2018 by the AUTHORS.

This is free software, dual licensed under:

Expand Down
4 changes: 3 additions & 1 deletion META.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,14 @@
"IO::String" : "0",
"JSON::MaybeXS" : "1.002005",
"Module::Pluggable::Object" : "5.1",
"POSIX" : "0",
"Pod::Perldoc" : "0",
"Scalar::Util" : "0",
"Text::Autoformat" : "0",
"Text::CSV" : "0",
"Tie::Array" : "0",
"Tie::Hash" : "0"
"Tie::Hash" : "0",
"Time::ParseDate" : "2013.1113"
}
},
"test" : {
Expand Down
8 changes: 6 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ my %WriteMakefileArgs = (
"IO::String" => 0,
"JSON::MaybeXS" => "1.002005",
"Module::Pluggable::Object" => "5.1",
"POSIX" => 0,
"Pod::Perldoc" => 0,
"Scalar::Util" => 0,
"Text::Autoformat" => 0,
"Text::CSV" => 0,
"Tie::Array" => 0,
"Tie::Hash" => 0
"Tie::Hash" => 0,
"Time::ParseDate" => "2013.1113"
},
"TEST_REQUIRES" => {
"File::Spec::Functions" => 0,
Expand Down Expand Up @@ -119,13 +121,15 @@ my %FallbackPrereqs = (
"JSON::MaybeXS" => "1.002005",
"Module::Pluggable::Object" => "5.1",
"Module::Versions::Report" => "1.06",
"POSIX" => 0,
"Pod::Perldoc" => 0,
"Scalar::Util" => 0,
"Test::More" => "0.88",
"Text::Autoformat" => 0,
"Text::CSV" => 0,
"Tie::Array" => 0,
"Tie::Hash" => 0
"Tie::Hash" => 0,
"Time::ParseDate" => "2013.1113"
);

unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
Expand Down
2 changes: 2 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ requires 'IO::String';
requires 'JSON::MaybeXS', '1.002005';
requires 'Module::Pluggable::Object', '5.1';
requires 'Pod::Perldoc';
requires 'POSIX';
requires 'Scalar::Util';
requires 'Text::Autoformat';
requires 'Text::CSV';
requires 'Tie::Array';
requires 'Tie::Hash'; # includes Tie::ExtraHash
requires 'Time::ParseDate', '2013.1113';

# XS deps
recommends 'Cpanel::JSON::XS',
Expand Down
205 changes: 205 additions & 0 deletions fatlib/Time/CTime.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
package Time::CTime;


require 5.000;

use Time::Timezone;
use Time::CTime;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(ctime asctime strftime);
@EXPORT_OK = qw(asctime_n ctime_n @DoW @MoY @DayOfWeek @MonthOfYear);

use strict;

# constants
use vars qw(@DoW @DayOfWeek @MoY @MonthOfYear %strftime_conversion $VERSION);
use vars qw($template $sec $min $hour $mday $mon $year $wday $yday $isdst);

$VERSION = 2011.0505;

CONFIG: {
@DoW = qw(Sun Mon Tue Wed Thu Fri Sat);
@DayOfWeek = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
@MoY = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@MonthOfYear = qw(January February March April May June
July August September October November December);

%strftime_conversion = (
'%', sub { '%' },
'a', sub { $DoW[$wday] },
'A', sub { $DayOfWeek[$wday] },
'b', sub { $MoY[$mon] },
'B', sub { $MonthOfYear[$mon] },
'c', sub { asctime_n($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst, "") },
'd', sub { sprintf("%02d", $mday); },
'D', sub { sprintf("%02d/%02d/%02d", $mon+1, $mday, $year%100) },
'e', sub { sprintf("%2d", $mday); },
'f', sub { fracprintf ("%3.3f", $sec); },
'F', sub { fracprintf ("%6.6f", $sec); },
'h', sub { $MoY[$mon] },
'H', sub { sprintf("%02d", $hour) },
'I', sub { sprintf("%02d", $hour % 12 || 12) },
'j', sub { sprintf("%03d", $yday + 1) },
'k', sub { sprintf("%2d", $hour); },
'l', sub { sprintf("%2d", $hour % 12 || 12) },
'm', sub { sprintf("%02d", $mon+1); },
'M', sub { sprintf("%02d", $min) },
'n', sub { "\n" },
'o', sub { sprintf("%d%s", $mday, (($mday < 20 && $mday > 3) ? 'th' : ($mday%10 == 1 ? "st" : ($mday%10 == 2 ? "nd" : ($mday%10 == 3 ? "rd" : "th"))))) },
'p', sub { $hour > 11 ? "PM" : "AM" },
'r', sub { sprintf("%02d:%02d:%02d %s", $hour % 12 || 12, $min, $sec, $hour > 11 ? 'PM' : 'AM') },
'R', sub { sprintf("%02d:%02d", $hour, $min) },
'S', sub { sprintf("%02d", $sec) },
't', sub { "\t" },
'T', sub { sprintf("%02d:%02d:%02d", $hour, $min, $sec) },
'U', sub { wkyr(0, $wday, $yday) },
'v', sub { sprintf("%2d-%s-%4d", $mday, $MoY[$mon], $year+1900) },
'w', sub { $wday },
'W', sub { wkyr(1, $wday, $yday) },
'y', sub { sprintf("%02d",$year%100) },
'Y', sub { $year + 1900 },
'x', sub { sprintf("%02d/%02d/%02d", $mon + 1, $mday, $year%100) },
'X', sub { sprintf("%02d:%02d:%02d", $hour, $min, $sec) },
'Z', sub { &tz2zone(undef,undef,$isdst) }
# z sprintf("%+03d%02d", $offset / 3600, ($offset % 3600)/60);
);


}

sub fracprintf {
my($t,$s) = @_;
my($p) = sprintf($t, $s-int($s));
$p=~s/^0+//;
$p;
}

sub asctime_n {
my($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst, $TZname) = @_;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst, $TZname) = localtime($sec) unless defined $min;
$year += 1900;
$TZname .= ' '
if $TZname;
sprintf("%s %s %2d %2d:%02d:%02d %s%4d",
$DoW[$wday], $MoY[$mon], $mday, $hour, $min, $sec, $TZname, $year);
}

sub asctime
{
return asctime_n(@_)."\n";
}

# is this formula right?
sub wkyr {
my($wstart, $wday, $yday) = @_;
$wday = ($wday + 7 - $wstart) % 7;
return int(($yday - $wday + 13) / 7 - 1);
}

# ctime($time)

sub ctime {
my($time) = @_;
asctime(localtime($time), &tz2zone(undef,$time));
}

sub ctime_n {
my($time) = @_;
asctime_n(localtime($time), &tz2zone(undef,$time));
}

# strftime($template, @time_struct)
#
# Does not support locales

sub strftime {
local ($template, $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = @_;

undef $@;
$template =~ s/%([%aAbBcdDefFhHIjklmMnopQrRStTUvwWxXyYZ])/&{$Time::CTime::strftime_conversion{$1}}()/egs;
die $@ if $@;
return $template;
}

1;

__END__

=head1 NAME

Time::CTime -- format times ala POSIX asctime

=head1 SYNOPSIS

use Time::CTime
print ctime(time);
print asctime(localtime(time));
print strftime(template, localtime(time));

=head2 strftime conversions

%% PERCENT
%a day of the week abbr
%A day of the week
%b month abbr
%B month
%c ctime format: Sat Nov 19 21:05:57 1994
%d DD
%D MM/DD/YY
%e numeric day of the month
%f floating point seconds (milliseconds): .314
%F floating point seconds (microseconds): .314159
%h month abbr
%H hour, 24 hour clock, leading 0's)
%I hour, 12 hour clock, leading 0's)
%j day of the year
%k hour
%l hour, 12 hour clock
%m month number, starting with 1, leading 0's
%M minute, leading 0's
%n NEWLINE
%o ornate day of month -- "1st", "2nd", "25th", etc.
%p AM or PM
%r time format: 09:05:57 PM
%R time format: 21:05
%S seconds, leading 0's
%t TAB
%T time format: 21:05:57
%U week number, Sunday as first day of week
%v DD-Mon-Year
%w day of the week, numerically, Sunday == 0
%W week number, Monday as first day of week
%x date format: 11/19/94
%X time format: 21:05:57
%y year (2 digits)
%Y year (4 digits)
%Z timezone in ascii. eg: PST

=head1 DESCRIPTION

This module provides routines to format dates. They correspond
to the libc routines. &strftime() supports a pretty good set of
conversions -- more than most C libraries.

strftime supports a pretty good set of conversions.

The POSIX module has very similar functionality. You should consider
using it instead if you do not have allergic reactions to system
libraries.

=head1 GENESIS

Written by David Muir Sharnoff <muir@idiom.org>.

The starting point for this package was a posting by
Paul Foley <paul@ascent.com>

=head1 LICENSE

Copyright (C) 1996-2010 David Muir Sharnoff.
Copyright (C) 2011 Google, Inc.
License hereby
granted for anyone to use, modify or redistribute this module at
their own risk. Please feed useful changes back to cpan@dave.sharnoff.org.

83 changes: 83 additions & 0 deletions fatlib/Time/DaysInMonth.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package Time::DaysInMonth;

use Carp;

require 5.000;

@ISA = qw(Exporter);
@EXPORT = qw(days_in is_leap);
@EXPORT_OK = qw(%mltable);

use strict;

use vars qw($VERSION %mltable);

$VERSION = 99.1117;

CONFIG: {
%mltable = qw(
1 31
3 31
4 30
5 31
6 30
7 31
8 31
9 30
10 31
11 30
12 31);
}

sub days_in
{
# Month is 1..12
my ($year, $month) = @_;
return $mltable{$month+0} unless $month == 2;
return 28 unless &is_leap($year);
return 29;
}

sub is_leap
{
my ($year) = @_;
return 0 unless $year % 4 == 0;
return 1 unless $year % 100 == 0;
return 0 unless $year % 400 == 0;
return 1;
}

1;

__END__

=head1 NAME

Time::DaysInMonth -- simply report the number of days in a month

=head1 SYNOPSIS

use Time::DaysInMonth;
$days = days_in($year, $month_1_to_12);
$leapyear = is_leap($year);

=head1 DESCRIPTION

DaysInMonth is simply a package to report the number of days in
a month. That's all it does. Really!

=head1 AUTHOR

David Muir Sharnoff <muir@idiom.org>

=head1 BUGS

This only deals with the "modern" calendar. Look elsewhere for
historical time and date support.

=head1 LICENSE

Copyright (C) 1996-1999 David Muir Sharnoff. License hereby
granted for anyone to use, modify or redistribute this module at
their own risk. Please feed useful changes back to muir@idiom.org.

Loading