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]
Commit
e588ee26b152d952501beb167a506f6f0a6b2eab757d5744c85982a9c72c863d
Parent
eff2b2b9b076068…
1 file changed
+17
-4
+17
-4
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -168,27 +168,40 @@ | ||
| 168 | 168 | ** comparison. So add in missing factional seconds or seconds or time. |
| 169 | 169 | ** |
| 170 | 170 | ** The returned string is held in a static buffer that is overwritten |
| 171 | 171 | ** with each call, or else is just a copy of its input if there are |
| 172 | 172 | ** no changes. |
| 173 | +** | |
| 174 | +** For reference: | |
| 175 | +** | |
| 176 | +** 0123456789 123456789 1234 | |
| 177 | +** YYYY-MM-DD HH:MM:SS.SSSz | |
| 173 | 178 | */ |
| 174 | 179 | const char *fossil_roundup_date(const char *zDate){ |
| 175 | - static char zUp[24]; | |
| 180 | + static char zUp[28]; | |
| 176 | 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 | + } | |
| 177 | 187 | if( n==19 ){ /* YYYY-MM-DD HH:MM:SS */ |
| 178 | 188 | memcpy(zUp, zDate, 19); |
| 179 | - memcpy(zUp+19, ".999", 5); | |
| 189 | + memcpy(zUp+19, ".999z", 6); | |
| 190 | + if( !addZ ) zUp[23] = 0; | |
| 180 | 191 | return zUp; |
| 181 | 192 | } |
| 182 | 193 | if( n==16 ){ /* YYYY-MM-DD HH:MM */ |
| 183 | 194 | memcpy(zUp, zDate, 16); |
| 184 | - memcpy(zUp+16, ":59.999", 8); | |
| 195 | + memcpy(zUp+16, ":59.999z", 8); | |
| 196 | + if( !addZ ) zUp[23] = 0; | |
| 185 | 197 | return zUp; |
| 186 | 198 | } |
| 187 | 199 | if( n==10 ){ /* YYYY-MM-DD */ |
| 188 | 200 | 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; | |
| 190 | 203 | return zUp; |
| 191 | 204 | } |
| 192 | 205 | return zDate; |
| 193 | 206 | } |
| 194 | 207 | |
| 195 | 208 |
| --- 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 |