Fossil SCM

Access the "Z" zulu-timezone designator on the end of punctuation-less datetime values.

drh 2024-12-26 11:51 trunk
Commit c464947f8dee606d35a0333212373621caeb22cfe1de4c22c5d37ac7d9fb2177
1 file changed +19 -6
+19 -6
--- src/name.c
+++ src/name.c
@@ -65,33 +65,46 @@
6565
** the string is a hash prefix and NULL is returned if it is. If the
6666
** bVerifyNotAHash flag is false, then the result is determined by syntax
6767
** of the input string only, without reference to the artifact table.
6868
*/
6969
char *fossil_expand_datetime(const char *zIn, int bVerifyNotAHash){
70
- static char zEDate[20];
70
+ static char zEDate[24];
7171
static const char aPunct[] = { 0, 0, '-', '-', ' ', ':', ':' };
7272
int n = (int)strlen(zIn);
7373
int i, j;
74
+ int addZulu = 0;
7475
75
- /* Only three forms allowed:
76
+ /* These forms are allowed:
77
+ **
7678
** (1) YYYYMMDD
7779
** (2) YYYYMMDDHHMM
7880
** (3) YYYYMMDDHHMMSS
81
+ **
82
+ ** Forms (2) and (3) may be followed by a "Z" zulu timezone designator,
83
+ ** which is carried through into the output.
7984
*/
80
- if( n!=8 && n!=12 && n!=14 ) return 0;
85
+ if( n!=8 && n!=12 && n!=14 ){
86
+ if( (n==13 || n==15) && (zIn[12]=='z' || zIn[12]=='Z') ){
87
+ n--;
88
+ addZulu = 1;
89
+ }else{
90
+ return 0;
91
+ }
92
+ }
8193
8294
/* Every character must be a digit */
8395
for(i=0; fossil_isdigit(zIn[i]); i++){}
84
- if( i!=n ) return 0;
96
+ if( i!=n && (!addZulu || i!=n+1) ) return 0;
8597
8698
/* Expand the date */
87
- for(i=j=0; zIn[i]; i++){
99
+ for(i=j=0; i<n; i++){
88100
if( i>=4 && (i%2)==0 ){
89101
zEDate[j++] = aPunct[i/2];
90102
}
91103
zEDate[j++] = zIn[i];
92104
}
105
+ if( addZulu ) zEDate[j++] = 'Z';
93106
zEDate[j] = 0;
94107
95108
/* Check for reasonable date values.
96109
** Offset references:
97110
** YYYY-MM-DD HH:MM:SS
@@ -111,11 +124,11 @@
111124
if( i>60 ) return 0;
112125
if( n==14 && atoi(zEDate+17)>60 ) return 0;
113126
}
114127
115128
/* The string is not also a hash prefix */
116
- if( bVerifyNotAHash ){
129
+ if( bVerifyNotAHash && !addZulu ){
117130
if( db_exists("SELECT 1 FROM blob WHERE uuid GLOB '%q*'",zIn) ) return 0;
118131
}
119132
120133
/* It looks like this may be a date. Return it with punctuation added. */
121134
return zEDate;
122135
--- src/name.c
+++ src/name.c
@@ -65,33 +65,46 @@
65 ** the string is a hash prefix and NULL is returned if it is. If the
66 ** bVerifyNotAHash flag is false, then the result is determined by syntax
67 ** of the input string only, without reference to the artifact table.
68 */
69 char *fossil_expand_datetime(const char *zIn, int bVerifyNotAHash){
70 static char zEDate[20];
71 static const char aPunct[] = { 0, 0, '-', '-', ' ', ':', ':' };
72 int n = (int)strlen(zIn);
73 int i, j;
 
74
75 /* Only three forms allowed:
 
76 ** (1) YYYYMMDD
77 ** (2) YYYYMMDDHHMM
78 ** (3) YYYYMMDDHHMMSS
 
 
 
79 */
80 if( n!=8 && n!=12 && n!=14 ) return 0;
 
 
 
 
 
 
 
81
82 /* Every character must be a digit */
83 for(i=0; fossil_isdigit(zIn[i]); i++){}
84 if( i!=n ) return 0;
85
86 /* Expand the date */
87 for(i=j=0; zIn[i]; i++){
88 if( i>=4 && (i%2)==0 ){
89 zEDate[j++] = aPunct[i/2];
90 }
91 zEDate[j++] = zIn[i];
92 }
 
93 zEDate[j] = 0;
94
95 /* Check for reasonable date values.
96 ** Offset references:
97 ** YYYY-MM-DD HH:MM:SS
@@ -111,11 +124,11 @@
111 if( i>60 ) return 0;
112 if( n==14 && atoi(zEDate+17)>60 ) return 0;
113 }
114
115 /* The string is not also a hash prefix */
116 if( bVerifyNotAHash ){
117 if( db_exists("SELECT 1 FROM blob WHERE uuid GLOB '%q*'",zIn) ) return 0;
118 }
119
120 /* It looks like this may be a date. Return it with punctuation added. */
121 return zEDate;
122
--- src/name.c
+++ src/name.c
@@ -65,33 +65,46 @@
65 ** the string is a hash prefix and NULL is returned if it is. If the
66 ** bVerifyNotAHash flag is false, then the result is determined by syntax
67 ** of the input string only, without reference to the artifact table.
68 */
69 char *fossil_expand_datetime(const char *zIn, int bVerifyNotAHash){
70 static char zEDate[24];
71 static const char aPunct[] = { 0, 0, '-', '-', ' ', ':', ':' };
72 int n = (int)strlen(zIn);
73 int i, j;
74 int addZulu = 0;
75
76 /* These forms are allowed:
77 **
78 ** (1) YYYYMMDD
79 ** (2) YYYYMMDDHHMM
80 ** (3) YYYYMMDDHHMMSS
81 **
82 ** Forms (2) and (3) may be followed by a "Z" zulu timezone designator,
83 ** which is carried through into the output.
84 */
85 if( n!=8 && n!=12 && n!=14 ){
86 if( (n==13 || n==15) && (zIn[12]=='z' || zIn[12]=='Z') ){
87 n--;
88 addZulu = 1;
89 }else{
90 return 0;
91 }
92 }
93
94 /* Every character must be a digit */
95 for(i=0; fossil_isdigit(zIn[i]); i++){}
96 if( i!=n && (!addZulu || i!=n+1) ) return 0;
97
98 /* Expand the date */
99 for(i=j=0; i<n; i++){
100 if( i>=4 && (i%2)==0 ){
101 zEDate[j++] = aPunct[i/2];
102 }
103 zEDate[j++] = zIn[i];
104 }
105 if( addZulu ) zEDate[j++] = 'Z';
106 zEDate[j] = 0;
107
108 /* Check for reasonable date values.
109 ** Offset references:
110 ** YYYY-MM-DD HH:MM:SS
@@ -111,11 +124,11 @@
124 if( i>60 ) return 0;
125 if( n==14 && atoi(zEDate+17)>60 ) return 0;
126 }
127
128 /* The string is not also a hash prefix */
129 if( bVerifyNotAHash && !addZulu ){
130 if( db_exists("SELECT 1 FROM blob WHERE uuid GLOB '%q*'",zIn) ) return 0;
131 }
132
133 /* It looks like this may be a date. Return it with punctuation added. */
134 return zEDate;
135

Keyboard Shortcuts

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