Fossil SCM

Correctly round up fully expanded date/times even if they have a "Z" zulu-time indicator at the end. Fix for the issue identified in [forum:/forumpost/47082fbda8|forum post 47082fbda8]

drh 2025-03-19 18:03 trunk
Commit e588ee26b152d952501beb167a506f6f0a6b2eab757d5744c85982a9c72c863d
1 file changed +17 -4
+17 -4
--- src/name.c
+++ src/name.c
@@ -168,27 +168,40 @@
168168
** comparison. So add in missing factional seconds or seconds or time.
169169
**
170170
** The returned string is held in a static buffer that is overwritten
171171
** with each call, or else is just a copy of its input if there are
172172
** no changes.
173
+**
174
+** For reference:
175
+**
176
+** 0123456789 123456789 1234
177
+** YYYY-MM-DD HH:MM:SS.SSSz
173178
*/
174179
const char *fossil_roundup_date(const char *zDate){
175
- static char zUp[24];
180
+ static char zUp[28];
176181
int n = (int)strlen(zDate);
182
+ int addZ = 0;
183
+ if( n>10 && (zDate[n-1]=='z' || zDate[n-1]=='Z') ){
184
+ n--;
185
+ addZ = 1;
186
+ }
177187
if( n==19 ){ /* YYYY-MM-DD HH:MM:SS */
178188
memcpy(zUp, zDate, 19);
179
- memcpy(zUp+19, ".999", 5);
189
+ memcpy(zUp+19, ".999z", 6);
190
+ if( !addZ ) zUp[23] = 0;
180191
return zUp;
181192
}
182193
if( n==16 ){ /* YYYY-MM-DD HH:MM */
183194
memcpy(zUp, zDate, 16);
184
- memcpy(zUp+16, ":59.999", 8);
195
+ memcpy(zUp+16, ":59.999z", 8);
196
+ if( !addZ ) zUp[23] = 0;
185197
return zUp;
186198
}
187199
if( n==10 ){ /* YYYY-MM-DD */
188200
memcpy(zUp, zDate, 10);
189
- memcpy(zUp+10, " 23:59:59.999", 14);
201
+ memcpy(zUp+10, " 23:59:59.999z", 14);
202
+ if( !addZ ) zUp[23] = 0;
190203
return zUp;
191204
}
192205
return zDate;
193206
}
194207
195208
--- src/name.c
+++ src/name.c
@@ -168,27 +168,40 @@
168 ** comparison. So add in missing factional seconds or seconds or time.
169 **
170 ** The returned string is held in a static buffer that is overwritten
171 ** with each call, or else is just a copy of its input if there are
172 ** no changes.
 
 
 
 
 
173 */
174 const char *fossil_roundup_date(const char *zDate){
175 static char zUp[24];
176 int n = (int)strlen(zDate);
 
 
 
 
 
177 if( n==19 ){ /* YYYY-MM-DD HH:MM:SS */
178 memcpy(zUp, zDate, 19);
179 memcpy(zUp+19, ".999", 5);
 
180 return zUp;
181 }
182 if( n==16 ){ /* YYYY-MM-DD HH:MM */
183 memcpy(zUp, zDate, 16);
184 memcpy(zUp+16, ":59.999", 8);
 
185 return zUp;
186 }
187 if( n==10 ){ /* YYYY-MM-DD */
188 memcpy(zUp, zDate, 10);
189 memcpy(zUp+10, " 23:59:59.999", 14);
 
190 return zUp;
191 }
192 return zDate;
193 }
194
195
--- src/name.c
+++ src/name.c
@@ -168,27 +168,40 @@
168 ** comparison. So add in missing factional seconds or seconds or time.
169 **
170 ** The returned string is held in a static buffer that is overwritten
171 ** with each call, or else is just a copy of its input if there are
172 ** no changes.
173 **
174 ** For reference:
175 **
176 ** 0123456789 123456789 1234
177 ** YYYY-MM-DD HH:MM:SS.SSSz
178 */
179 const char *fossil_roundup_date(const char *zDate){
180 static char zUp[28];
181 int n = (int)strlen(zDate);
182 int addZ = 0;
183 if( n>10 && (zDate[n-1]=='z' || zDate[n-1]=='Z') ){
184 n--;
185 addZ = 1;
186 }
187 if( n==19 ){ /* YYYY-MM-DD HH:MM:SS */
188 memcpy(zUp, zDate, 19);
189 memcpy(zUp+19, ".999z", 6);
190 if( !addZ ) zUp[23] = 0;
191 return zUp;
192 }
193 if( n==16 ){ /* YYYY-MM-DD HH:MM */
194 memcpy(zUp, zDate, 16);
195 memcpy(zUp+16, ":59.999z", 8);
196 if( !addZ ) zUp[23] = 0;
197 return zUp;
198 }
199 if( n==10 ){ /* YYYY-MM-DD */
200 memcpy(zUp, zDate, 10);
201 memcpy(zUp+10, " 23:59:59.999z", 14);
202 if( !addZ ) zUp[23] = 0;
203 return zUp;
204 }
205 return zDate;
206 }
207
208

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button