Skip Menu |

This queue is for tickets about the Class-Date CPAN distribution.

Report information
The Basics
Id: 19104
Status: resolved
Priority: 0/
Queue: Class-Date

People
Owner: Nobody in particular
Requestors: llarian [...] llarian.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Patch: adds ampm and meridiam methods.
I found I needed this functionality for a project using Class::Date. My naming kinda sucks, but I figured I'd send along the patch anyways in case you wanted to include something with that concept. I've found it incredibly useful when using Class::Date with templates.
Subject: class-date-meridiam.patch
Common subdirectories: Class-Date-1.1.8.orig/Date and Class-Date-1.1.8/Date diff -u Class-Date-1.1.8.orig/Date.pm Class-Date-1.1.8/Date.pm --- Class-Date-1.1.8.orig/Date.pm 2005-11-06 07:25:09.000000000 -0800 +++ Class-Date-1.1.8/Date.pm 2006-05-05 12:56:20.000000000 -0700 @@ -388,6 +388,16 @@ return $s; } +sub ampm { my ($s) = @_; + return $s->[c_hour] < 12 ? "AM" : "PM"; +} + +sub meridiam { my ($s) = @_; + my $hour = $s->[c_hour] % 12; + if( $hour == 0 ) { $hour = 12; } + sprintf('%02d:%02d %s', $hour, $s->[c_min], $s->ampm); +} + sub hms { sprintf('%02d:%02d:%02d', @{ shift() }[c_hour,c_min,c_sec]) } sub ymd { my ($s)=@_; diff -u Class-Date-1.1.8.orig/Date.pod Class-Date-1.1.8/Date.pod --- Class-Date-1.1.8.orig/Date.pod 2005-11-06 07:32:54.000000000 -0800 +++ Class-Date-1.1.8/Date.pod 2006-05-05 12:56:54.000000000 -0700 @@ -73,6 +73,8 @@ $date->ymd # 2000/02/29 $date->mdy # 02/29/2000 $date->dmy # 29/02/2000 + $date->meridiam # 01:23 AM + $date->ampm # AM/PM $date->string # 2000-02-29 12:21:11 (format can be changed, look below) "$date" # same as prev. $date->tzoffset # timezone-offset Only in Class-Date-1.1.8: Makefile.old diff -u Class-Date-1.1.8.orig/README Class-Date-1.1.8/README --- Class-Date-1.1.8.orig/README 2005-11-06 07:37:44.000000000 -0800 +++ Class-Date-1.1.8/README 2006-05-05 11:44:37.000000000 -0700 @@ -71,6 +71,8 @@ $date->ymd # 2000/02/29 $date->mdy # 02/29/2000 $date->dmy # 29/02/2000 + $date->meridiam # 01:23 AM + $date->ampm # AM/PM $date->string # 2000-02-29 12:21:11 (format can be changed, look below) "$date" # same as prev. $date->tzoffset # timezone-offset Common subdirectories: Class-Date-1.1.8.orig/t and Class-Date-1.1.8/t