[前][次][番号順一覧][スレッド一覧]

ruby-changes:19878

From: tadf <ko1@a...>
Date: Sun, 5 Jun 2011 17:54:05 +0900 (JST)
Subject: [ruby-changes:19878] tadf:r31925 (trunk): * ext/date/date_core.c (m_real_cwyear): new. derived from m_cwyear.

tadf	2011-06-05 17:53:56 +0900 (Sun, 05 Jun 2011)

  New Revision: 31925

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31925

  Log:
    * ext/date/date_core.c (m_real_cwyear): new.  derived from m_cwyear.
    * ext/date/date_strftime.c: trivial changes.

  Modified files:
    trunk/ChangeLog
    trunk/ext/date/date_core.c
    trunk/ext/date/date_strftime.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31924)
+++ ChangeLog	(revision 31925)
@@ -1,3 +1,8 @@
+Sun Jun  5 17:50:01 2011  Tadayoshi Funaba  <tadf@d...>
+
+	* ext/date/date_core.c (m_real_cwyear): new.  derived from m_cwyear.
+	* ext/date/date_strftime.c: trivial changes.
+
 Sun Jun  5 17:22:01 2011  Hidetoshi NAGAI  <nagai@a...>
 
 	* ext/tk/config_list.in: add new options for tcltklib.
Index: ext/date/date_core.c
===================================================================
--- ext/date/date_core.c	(revision 31924)
+++ ext/date/date_core.c	(revision 31925)
@@ -1707,20 +1707,34 @@
     return c_jd_to_wday(m_local_jd(x));
 }
 
-static VALUE
+static int
 m_cwyear(union DateData *x)
 {
-    double sg;
     int ry, rw, rd;
-    VALUE ry2;
 
-    sg = x_sg(x); /* !=m_sg() */
-    c_jd_to_commercial(m_local_jd(x), sg,
+    c_jd_to_commercial(m_local_jd(x), x_sg(x), /* !=m_sg() */
 		       &ry, &rw, &rd);
-    encode_year(m_nth(x), ry, sg, &ry2);
-    return ry2;
+    return ry;
 }
 
+static VALUE
+m_real_cwyear(union DateData *x)
+{
+    VALUE nth, ry;
+    int year;
+
+    nth = m_nth(x);
+    year = m_cwyear(x);
+
+    if (f_zero_p(nth))
+	return INT2FIX(year);
+
+    encode_year(nth, year,
+		m_gregorian_p(x) ? -1 : +1,
+		&ry);
+    return ry;
+}
+
 static int
 m_cweek(union DateData *x)
 {
@@ -4716,7 +4730,7 @@
 d_lite_cwyear(VALUE self)
 {
     get_d1(self);
-    return m_cwyear(dat);
+    return m_real_cwyear(dat);
 }
 
 /*
@@ -6396,7 +6410,7 @@
     (int (*)(void *))m_yday,
     (int (*)(void *))m_mon,
     (int (*)(void *))m_mday,
-    (VALUE (*)(void *))m_cwyear,
+    (VALUE (*)(void *))m_real_cwyear,
     (int (*)(void *))m_cweek,
     (int (*)(void *))m_cwday,
     (int (*)(void *))m_wnum0,
Index: ext/date/date_strftime.c
===================================================================
--- ext/date/date_strftime.c	(revision 31924)
+++ ext/date/date_strftime.c	(revision 31925)
@@ -180,7 +180,6 @@
 	long off;
 	ptrdiff_t i;
 	int w;
-	long y;
 	int precision, flags, colons;
 	char padding;
 	enum {LEFT, CHCASE, LOWER, UPPER, LOCALE_O, LOCALE_E};
@@ -300,10 +299,13 @@
 				flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
 				flags |= BIT_OF(UPPER);
 			}
-			if (tmx_wday < 0 || tmx_wday > 6)
-				i = 1, tp = "?";
-			else
-				i = 3, tp = days_l[tmx_wday];
+			{
+				int wday = tmx_wday;
+				if (wday < 0 || wday > 6)
+					i = 1, tp = "?";
+				else
+					i = 3, tp = days_l[wday];
+			}
 			break;
 
 		case 'A':	/* full weekday name */
@@ -311,10 +313,13 @@
 				flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
 				flags |= BIT_OF(UPPER);
 			}
-			if (tmx_wday < 0 || tmx_wday > 6)
-				i = 1, tp = "?";
-			else
-				i = strlen(tp = days_l[tmx_wday]);
+			{
+				int wday = tmx_wday;
+				if (wday < 0 || wday > 6)
+					i = 1, tp = "?";
+				else
+					i = strlen(tp = days_l[wday]);
+			}
 			break;
 
 #ifdef SYSV_EXT
@@ -325,10 +330,13 @@
 				flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
 				flags |= BIT_OF(UPPER);
 			}
-			if (tmx_mon < 1 || tmx_mon > 12)
-				i = 1, tp = "?";
-			else
-				i = 3, tp = months_l[tmx_mon-1];
+			{
+				int mon = tmx_mon;
+				if (mon < 1 || mon > 12)
+					i = 1, tp = "?";
+				else
+					i = 3, tp = months_l[mon-1];
+			}
 			break;
 
 		case 'B':	/* full month name */
@@ -336,10 +344,13 @@
 				flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
 				flags |= BIT_OF(UPPER);
 			}
-			if (tmx_mon < 1 || tmx_mon > 12)
-				i = 1, tp = "?";
-			else
-				i = strlen(tp = months_l[tmx_mon-1]);
+			{
+				int mon = tmx_mon;
+				if (mon < 1 || mon > 12)
+					i = 1, tp = "?";
+				else
+					i = strlen(tp = months_l[mon-1]);
+			}
 			break;
 
 		case 'c':	/* appropriate date and time representation */
@@ -410,8 +421,8 @@
 			}
                         continue;
 
-		case 'S':	/* second, 00 - 60 */
-			i = range(0, tmx_sec, 60);
+		case 'S':	/* second, 00 - 59 */
+			i = range(0, tmx_sec, 59);
 			FMT('0', 2, "d", (int)i);
 			continue;
 
@@ -442,13 +453,16 @@
 			continue;
 
 		case 'Y':	/* year with century */
-                        if (FIXNUM_P(tmx_year)) {
-                            long y = FIX2LONG(tmx_year);
-                            FMT('0', 0 <= y ? 4 : 5, "ld", y);
-                        }
-                        else {
-                            FMTV('0', 4, "d", tmx_year);
-                        }
+			{
+				VALUE year = tmx_year;
+				if (FIXNUM_P(year)) {
+					long y = FIX2LONG(year);
+					FMT('0', 0 <= y ? 4 : 5, "ld", y);
+				}
+				else {
+					FMTV('0', 4, "d", year);
+				}
+			}
 			continue;
 
 #ifdef MAILHEADER_EXT
@@ -549,11 +563,14 @@
 				flags &= ~(BIT_OF(UPPER)|BIT_OF(CHCASE));
 				flags |= BIT_OF(LOWER);
 			}
-                        if (tmx_zone == NULL)
-                            tp = "";
-                        else
-                            tp = tmx_zone;
-			i = strlen(tp);
+			{
+				char *zone = tmx_zone;
+				if (zone == NULL)
+					tp = "";
+				else
+					tp = zone;
+				i = strlen(tp);
+			}
 			break;
 
 #ifdef SYSV_EXT
@@ -639,24 +656,21 @@
 #endif	/* POSIX2_DATE */
 
 #ifdef ISO_DATE_EXT
-		case 'G':
-		case 'g':
+		case 'g':	/* year of ISO week without a century */
+			i = NUM2INT(mod(tmx_cwyear, INT2FIX(100)));
+			FMT('0', 2, "d", (int)i);
+			continue;
+
+		case 'G':	/* year of ISO week with century */
 			{
-				VALUE yv = tmx_cwyear;
-                                if (*format == 'G') {
-					if (FIXNUM_P(yv)) {
-						long y = FIX2LONG(yv);
-						FMT('0', 0 <= y ? 4 : 5, "ld", y);
-					}
-					else {
-						FMTV('0', 4, "d", yv);
-					}
+				VALUE year = tmx_cwyear;
+				if (FIXNUM_P(year)) {
+					long y = FIX2LONG(year);
+					FMT('0', 0 <= y ? 4 : 5, "ld", y);
 				}
-                                else {
-                                        yv = mod(yv, INT2FIX(100));
-                                        y = FIX2LONG(yv);
-                                        FMT('0', 2, "ld", y);
-                                }
+				else {
+					FMTV('0', 4, "d", year);
+				}
                                 continue;
 			}
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]