summaryrefslogtreecommitdiff
path: root/devel/icu4/files/patch-format
blob: 817d4fb1733b6cee51513fb614f8f81895085985 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
Fix self-test(s) breaking, when build happens on days with other than
24-hours (such as when daylight saving time kicks in). See:

	http://www.freebsd.org/cgi/query-pr.cgi?pr=128521
	http://www.icu-project.org/trac/ticket/6018

Index: /icu/trunk/source/i18n/calendar.cpp
===================================================================
--- i18n/calendar.cpp (revision 22978)
+++ i18n/calendar.cpp (revision 23166)
@@ -1,5 +1,5 @@
 /*
 *******************************************************************************
-* Copyright (C) 1997-2007, International Business Machines Corporation and    *
+* Copyright (C) 1997-2008, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
@@ -74,6 +74,12 @@
 
 #if defined( U_DEBUG_CALSVC ) || defined (U_DEBUG_CAL)
+
+/** 
+ * fldName was removed as a duplicate implementation. 
+ * use  udbg_ services instead, 
+ * which depend on include files and library from ../tools/ctestfw
+ */
+#include "unicode/udbgutil.h"
 #include <stdio.h>
-
 
 /**
@@ -83,12 +89,8 @@
 * @internal
 */
-#error fldName() has been removed. Please use udbg_ucal_fieldName()  from libctestfw instead. The following code might work.
-
-static const char* fldName(UCalendarDateFields f) {
-	const char *udbg_ucal_fieldName(int32_t fld);
-	return udbg_ucal_fieldName((int32_t)f);
-}
-
-
+
+const char* fldName(UCalendarDateFields f) {
+	return udbg_enumName(UDBG_UCalendarDateFields, (int32_t)f);
+}
 
 #if UCAL_DEBUG_DUMP
Index: /icu/trunk/source/i18n/reldtfmt.cpp
===================================================================
--- i18n/reldtfmt.cpp (revision 22561)
+++ i18n/reldtfmt.cpp (revision 23166)
@@ -1,5 +1,5 @@
 /*
 *******************************************************************************
-* Copyright (C) 2007, International Business Machines Corporation and    *
+* Copyright (C) 2007-2008, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
@@ -304,8 +304,13 @@
         return 0;
     }
-    // TODO: Cache the nowCal to avoid heap allocs?
+    // TODO: Cache the nowCal to avoid heap allocs? Would be difficult, don't know the calendar type
     Calendar *nowCal = cal.clone();
     nowCal->setTime(Calendar::getNow(), status);
-    int32_t dayDiff = nowCal->fieldDifference(cal.getTime(status), Calendar::DATE, status);
+
+    // For the day difference, we are interested in the difference in the (modified) julian day number
+    // which is midnight to midnight.  Using fieldDifference() is NOT correct here, because 
+    // 6pm Jan 4th  to 10am Jan 5th should be considered "tomorrow".
+    int32_t dayDiff = cal.get(UCAL_JULIAN_DAY, status) - nowCal->get(UCAL_JULIAN_DAY, status);
+
     delete nowCal;
     return dayDiff;
Index: /icu/trunk/source/test/intltest/dadrfmt.cpp
===================================================================
--- test/intltest/dadrfmt.cpp (revision 22493)
+++ test/intltest/dadrfmt.cpp (revision 23166)
@@ -1,5 +1,5 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2007, International Business Machines Corporation and
+ * Copyright (c) 1997-2008, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
@@ -94,4 +94,5 @@
     UnicodeString kMILLIS("MILLIS="); // TODO: static
     UnicodeString kRELATIVE_MILLIS("RELATIVE_MILLIS="); // TODO: static
+    UnicodeString kRELATIVE_ADD("RELATIVE_ADD:"); // TODO: static
     
     UErrorCode status = U_ZERO_ERROR;
@@ -170,5 +171,10 @@
             }
         }
-        
+
+        Calendar *cal = Calendar::createInstance(loc, status);
+        if(U_FAILURE(status)) {
+            errln("case %d: could not create calendar from %s", n, calLoc);
+        }
+
         // parse 'date'
         if(date.startsWith(kMILLIS)) {
@@ -180,4 +186,28 @@
             useDate = TRUE;
             fromDate = udbg_stoi(millis) + now;
+        } else if(date.startsWith(kRELATIVE_ADD)) {
+            UnicodeString add = UnicodeString(date, kRELATIVE_ADD.length());  // "add" is a string indicating which fields to add
+            if(fromSet.parseFrom(add, status)<0 || U_FAILURE(status)) {
+                errln("case %d: could not parse date as RELATIVE_ADD calendar fields: %s", n, u_errorName(status));
+                continue;
+            }
+            logln("Parsing ..\n");
+            useDate=TRUE;
+            cal->clear();
+            cal->setTime(now, status);
+            for (int q=0; q<UCAL_FIELD_COUNT; q++) {
+                if (fromSet.isSet((UCalendarDateFields)q)) {
+                    int32_t oldv = cal->get((UCalendarDateFields)q, status);
+                    cal->add((UCalendarDateFields)q,
+                                fromSet.get((UCalendarDateFields)q), status);
+                    int32_t newv = cal->get((UCalendarDateFields)q, status);
+                    logln("adding %d to %s ..went from %d to %d\n", fromSet.get((UCalendarDateFields)q), udbg_enumName(UDBG_UCalendarDateFields, q), oldv, newv);
+                }
+            }
+            fromDate = cal->getTime(status);
+            if(U_FAILURE(status)) {
+                errln("case %d: could not apply date as RELATIVE_ADD calendar fields: %s", n, u_errorName(status));
+                continue;
+            }
         } else if(fromSet.parseFrom(date, status)<0 || U_FAILURE(status)) {
             errln("case %d: could not parse date as calendar fields: %s", n, u_errorName(status));
@@ -185,8 +215,4 @@
         }
         
-        Calendar *cal = Calendar::createInstance(loc, status);
-        if(U_FAILURE(status)) {
-            errln("case %d: could not create calendar from %s", n, calLoc);
-        }
         // now, do it.
         if (fmt) {
Index: /icu/trunk/source/test/testdata/format.txt
===================================================================
--- test/testdata/format.txt (revision 22885)
+++ test/testdata/format.txt (revision 23166)
@@ -1,3 +1,3 @@
-// Copyright (c) 2007 International Business Machines
+// Copyright (c) 2007-2008 International Business Machines
 // Corporation and others. All Rights Reserved.
 format:table(nofallback) {
@@ -23,5 +23,8 @@
             // locale: locale including calendar type
             // spec:   either 'PATTERN=y mm h' etc, or 'DATE=SHORT,TIME=LONG'
-            // date:   either 'MILLIS=####' where #### is an unsigned long (millis), or a calendar spec ERA=0,YEAR=1, etc.. applied to the calendar type specified by the locale
+            // date:   either 'MILLIS=####' where #### is millis,
+            //        or a calendar spec ERA=0,YEAR=1, etc.. applied to the calendar type specified by the locale
+            //        or RELATIVE_MILLIS=### where ### is a signed value which is added to the current millis
+            //        or RELATIVE_ADD:DATE=1  which means that the field "DATE" will be added by +1 relative to current time
             // str:   the expected unicode string
             Cases { 
@@ -61,5 +64,5 @@
                     "en_US@calendar=gregorian",         
                     "DATE=RELATIVE_SHORT",
-                    "RELATIVE_MILLIS=86410000", // one day from now
+                    "RELATIVE_ADD:DATE=1", // one day from now
                     "Tomorrow"
                },
@@ -67,5 +70,5 @@
                     "en_US@calendar=gregorian",         
                     "DATE=RELATIVE_SHORT",
-                    "RELATIVE_MILLIS=0", // one day before now
+                    "RELATIVE_MILLIS=0", // today
                     "Today"
                },
@@ -73,5 +76,5 @@
                     "en_US@calendar=gregorian",         
                     "DATE=RELATIVE_SHORT",
-                    "RELATIVE_MILLIS=-86410000", // one day before now
+                    "RELATIVE_ADD:DATE=-1", // one day before now
                     "Yesterday"
                },
@@ -79,5 +82,5 @@
                     "mt_MT@calendar=gregorian",         
                     "DATE=RELATIVE_SHORT",
-                    "RELATIVE_MILLIS=86410000", // one day from now
+                    "RELATIVE_ADD:DATE=1", // one day from now
                     "Għada"
                },
@@ -85,5 +88,5 @@
                     "mt_MT@calendar=gregorian",         
                     "DATE=RELATIVE_SHORT",
-                    "RELATIVE_MILLIS=0", // one day before now
+                    "RELATIVE_MILLIS=0", // today
                     "Illum"
                },
@@ -91,5 +94,5 @@
                     "mt_MT@calendar=gregorian",         
                     "DATE=RELATIVE_SHORT",
-                    "RELATIVE_MILLIS=-86410000", // one day before now
+                    "RELATIVE_ADD:DATE=-1", // one day before now
                     "Lbieraħ"
                },
@@ -97,5 +100,5 @@
                     "ru",
                     "DATE=RELATIVE_SHORT",
-                    "RELATIVE_MILLIS=-172810000", // 2 days ago
+                    "RELATIVE_ADD:DATE=-2", // 2 days ago
                     "Позавчера"
                },