r54532 - in /branches/upstream/libtime-piece-perl/current: Changes META.yml Piece.pm Piece.xs Seconds.pm t/02core.t

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Fri Mar 19 02:22:07 UTC 2010


Author: jawnsy-guest
Date: Fri Mar 19 02:22:00 2010
New Revision: 54532

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=54532
Log:
[svn-upgrade] Integrating new upstream version, libtime-piece-perl (1.20)

Modified:
    branches/upstream/libtime-piece-perl/current/Changes
    branches/upstream/libtime-piece-perl/current/META.yml
    branches/upstream/libtime-piece-perl/current/Piece.pm
    branches/upstream/libtime-piece-perl/current/Piece.xs
    branches/upstream/libtime-piece-perl/current/Seconds.pm
    branches/upstream/libtime-piece-perl/current/t/02core.t

Modified: branches/upstream/libtime-piece-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtime-piece-perl/current/Changes?rev=54532&op=diff
==============================================================================
--- branches/upstream/libtime-piece-perl/current/Changes (original)
+++ branches/upstream/libtime-piece-perl/current/Changes Fri Mar 19 02:22:00 2010
@@ -1,5 +1,10 @@
+Time::Piece Changes
 
-Time::Piece Changes
+1.20
+    - Fix for alloca broke Solaris
+    - Fixed documentation buggette about strptime
+    - Added ->pretty() method for Time::Seconds objects
+	- Add %s support to strptime
 
 1.19
     - Fix for alloca broke FreeBSD

Modified: branches/upstream/libtime-piece-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtime-piece-perl/current/META.yml?rev=54532&op=diff
==============================================================================
--- branches/upstream/libtime-piece-perl/current/META.yml (original)
+++ branches/upstream/libtime-piece-perl/current/META.yml Fri Mar 19 02:22:00 2010
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:                Time-Piece
-version:             1.19
+version:             1.20
 abstract:            Object Oriented time objects
 license:             ~
 author:              

Modified: branches/upstream/libtime-piece-perl/current/Piece.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtime-piece-perl/current/Piece.pm?rev=54532&op=diff
==============================================================================
--- branches/upstream/libtime-piece-perl/current/Piece.pm (original)
+++ branches/upstream/libtime-piece-perl/current/Piece.pm Fri Mar 19 02:22:00 2010
@@ -1,5 +1,3 @@
-# $Id: Piece.pm 93 2010-02-10 22:37:00Z matt $
-
 package Time::Piece;
 
 use strict;
@@ -21,7 +19,7 @@
     ':override' => 'internal',
     );
 
-our $VERSION = '1.19';
+our $VERSION = '1.20';
 
 bootstrap Time::Piece $VERSION;
 
@@ -786,10 +784,10 @@
 
 =head2 Date Parsing
 
-Time::Piece links to your C library's strptime() function, allowing
+Time::Piece has a built-in strptime() function (from FreeBSD), allowing
 you incredibly flexible date parsing routines. For example:
 
-  my $t = Time::Piece->strptime("Sun 3rd Nov, 1943",
+  my $t = Time::Piece->strptime("Sunday 3rd Nov, 1943",
                                 "%A %drd %b, %Y");
   
   print $t->strftime("%a, %d %b %Y");
@@ -802,6 +800,8 @@
 
 For more information see "man strptime", which should be on all unix
 systems.
+
+Alternatively look here: http://www.unix.com/man-page/FreeBSD/3/strftime/
 
 =head2 YYYY-MM-DDThh:mm:ss
 

Modified: branches/upstream/libtime-piece-perl/current/Piece.xs
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtime-piece-perl/current/Piece.xs?rev=54532&op=diff
==============================================================================
--- branches/upstream/libtime-piece-perl/current/Piece.xs (original)
+++ branches/upstream/libtime-piece-perl/current/Piece.xs Fri Mar 19 02:22:00 2010
@@ -314,8 +314,8 @@
 #define alloca _alloca
 #endif
 #else
-#if defined(_SGIAPI) || defined( __sgi )
-/* required for IRIX */
+#if defined(_SGIAPI) || defined( __sgi ) || ( defined (__SVR4) && defined (__sun) )
+/* required for IRIX and Solaris */
 #include <alloca.h>
 #endif
 #endif
@@ -467,13 +467,17 @@
 		len;
 	int Ealternative, Oalternative;
 
+    /* There seems to be a slightly improved version at
+     * http://www.opensource.apple.com/source/Libc/Libc-583/stdtime/strptime-fbsd.c
+     * which we may end up borrowing more from
+     */
 	ptr = fmt;
 	while (*ptr != 0) {
 		if (*buf == 0)
 			break;
 
 		c = *ptr++;
-
+		
 		if (c != '%') {
 			if (isspace((unsigned char)c))
 				while (*buf != 0 && isspace((unsigned char)*buf))
@@ -563,6 +567,14 @@
 				return 0;
 			break;
 
+		case 'n': /* whitespace */
+		case 't':
+			if (!isspace((unsigned char)*buf))
+				return 0;
+			while (isspace((unsigned char)*buf))
+				buf++;
+			break;
+		
 		case 'T':
 			buf = _strptime(aTHX_ buf, "%H:%M:%S", tm);
 			if (buf == 0)
@@ -639,7 +651,7 @@
 			 * XXX The %l specifier may gobble one too many
 			 * digits if used incorrectly.
 			 */
-                        if (!isdigit((unsigned char)*buf))
+            if (!isdigit((unsigned char)*buf))
 				return 0;
 
 			len = 2;
@@ -666,7 +678,7 @@
 			 * XXX This is bogus if parsed before hour-related
 			 * specifiers.
 			 */
-                        len = strlen(Locale->am);
+            len = strlen(Locale->am);
 			if (strncasecmp(buf, Locale->am, len) == 0) {
 				if (tm->tm_hour > 12)
 					return 0;
@@ -720,7 +732,7 @@
 			 * point to calculate a real value, so just check the
 			 * range for now.
 			 */
-                        if (!isdigit((unsigned char)*buf))
+            if (!isdigit((unsigned char)*buf))
 				return 0;
 
 			len = 2;
@@ -834,6 +846,38 @@
 			if (*buf != 0 && isspace((unsigned char)*buf))
 				while (*ptr != 0 && !isspace((unsigned char)*ptr))
 					ptr++;
+			break;
+
+		case 's':
+			{
+			char *cp;
+			int sverrno;
+			long n;
+			time_t t;
+            struct tm mytm;
+
+			sverrno = errno;
+			errno = 0;
+			n = strtol(buf, &cp, 10);
+			if (errno == ERANGE || (long)(t = n) != n) {
+				errno = sverrno;
+				return 0;
+			}
+			errno = sverrno;
+			buf = cp;
+            memset(&mytm, 0, sizeof(mytm));
+            my_init_tm(&mytm);    /* XXX workaround - see my_init_tm() above */
+            mytm = *gmtime(&t);
+            tm->tm_sec    = mytm.tm_sec;
+            tm->tm_min    = mytm.tm_min;
+            tm->tm_hour   = mytm.tm_hour;
+            tm->tm_mday   = mytm.tm_mday;
+            tm->tm_mon    = mytm.tm_mon;
+            tm->tm_year   = mytm.tm_year;
+            tm->tm_wday   = mytm.tm_wday;
+            tm->tm_yday   = mytm.tm_yday;
+            tm->tm_isdst  = mytm.tm_isdst;
+			}
 			break;
 
 		case 'Y':
@@ -1037,7 +1081,7 @@
        mytm = *gmtime(&t);
        remainder = (char *)our_strptime(aTHX_ string, format, &mytm);
        if (remainder == NULL) {
-	  croak("Error parsing time");
+           croak("Error parsing time");
        }
        if (*remainder != '\0') {
            warn("garbage at end of string in strptime: %s", remainder);

Modified: branches/upstream/libtime-piece-perl/current/Seconds.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtime-piece-perl/current/Seconds.pm?rev=54532&op=diff
==============================================================================
--- branches/upstream/libtime-piece-perl/current/Seconds.pm (original)
+++ branches/upstream/libtime-piece-perl/current/Seconds.pm Fri Mar 19 02:22:00 2010
@@ -1,25 +1,22 @@
-# $Id: Seconds.pm 69 2006-09-07 17:41:05Z matt $
-
 package Time::Seconds;
 use strict;
 use vars qw/@EXPORT @EXPORT_OK @ISA/;
-use UNIVERSAL qw(isa);
 
 @ISA = 'Exporter';
 
 @EXPORT = qw(
-		ONE_MINUTE 
-		ONE_HOUR 
-		ONE_DAY 
-		ONE_WEEK 
-		ONE_MONTH
-                ONE_REAL_MONTH
-		ONE_YEAR
-                ONE_REAL_YEAR
-		ONE_FINANCIAL_MONTH
-		LEAP_YEAR 
-		NON_LEAP_YEAR
-		);
+    ONE_MINUTE 
+    ONE_HOUR 
+    ONE_DAY 
+    ONE_WEEK 
+    ONE_MONTH
+    ONE_REAL_MONTH
+    ONE_YEAR
+    ONE_REAL_YEAR
+    ONE_FINANCIAL_MONTH
+    LEAP_YEAR 
+    NON_LEAP_YEAR
+);
 
 @EXPORT_OK = qw(cs_sec cs_mon);
 
@@ -41,10 +38,10 @@
 
 use overload 
                 'fallback' => 'undef',
-		'0+' => \&seconds,
-		'""' => \&seconds,
-		'<=>' => \&compare,
-		'+' => \&add,
+                '0+' => \&seconds,
+                '""' => \&seconds,
+                '<=>' => \&compare,
+                '+' => \&add,
                 '-' => \&subtract,
                 '-=' => \&subtract_from,
                 '+=' => \&add_to,
@@ -148,6 +145,32 @@
 sub years {
     my $s = shift;
     $s->days / 365.24225;
+}
+
+sub pretty {
+    my $s = shift;
+    my $str = "";
+    if ($s < 0) {
+        $s = -$s;
+        $str = "minus ";
+    }
+    if ($s >= ONE_MINUTE) {
+        if ($s >= ONE_HOUR) {
+            if ($s >= ONE_DAY) {
+                my $days = sprintf("%d", $s->days); # does a "floor"
+                $str = $days . " days, ";
+                $s -= ($days * ONE_DAY);
+            }
+            my $hours = sprintf("%d", $s->hours);
+            $str .= $hours . " hours, ";
+            $s -= ($hours * ONE_HOUR);
+        }
+        my $mins = sprintf("%d", $s->minutes);
+        $str .= $mins . " minutes, ";
+        $s -= ($mins * ONE_MINUTE);
+    }
+    $str .= $s->seconds . " seconds";
+    return $str;
 }
 
 1;
@@ -183,9 +206,9 @@
     ONE_WEEK
     ONE_HOUR
     ONE_MINUTE
-	ONE_MONTH
-	ONE_YEAR
-	ONE_FINANCIAL_MONTH
+    ONE_MONTH
+    ONE_YEAR
+    ONE_FINANCIAL_MONTH
     LEAP_YEAR
     NON_LEAP_YEAR
 
@@ -205,6 +228,9 @@
 	$val->months;
 	$val->financial_months; # 30 days
     $val->years;
+    $val->pretty; # gives English representation of the delta
+
+The usual arithmetic (+,-,+=,-=) is also available on the objects.
 
 The methods make the assumption that there are 24 hours in a day, 7 days in
 a week, 365.24225 days in a year and 12 months in a year.

Modified: branches/upstream/libtime-piece-perl/current/t/02core.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtime-piece-perl/current/t/02core.t?rev=54532&op=diff
==============================================================================
--- branches/upstream/libtime-piece-perl/current/t/02core.t (original)
+++ branches/upstream/libtime-piece-perl/current/t/02core.t Fri Mar 19 02:22:00 2010
@@ -219,3 +219,4 @@
   '==',
   951827696
 );
+




More information about the Pkg-perl-cvs-commits mailing list