Fossil SCM
Access the "Z" zulu-timezone designator on the end of punctuation-less datetime values.
Commit
c464947f8dee606d35a0333212373621caeb22cfe1de4c22c5d37ac7d9fb2177
Parent
b1bb31e838138c8…
1 file changed
+19
-6
+19
-6
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -65,33 +65,46 @@ | ||
| 65 | 65 | ** the string is a hash prefix and NULL is returned if it is. If the |
| 66 | 66 | ** bVerifyNotAHash flag is false, then the result is determined by syntax |
| 67 | 67 | ** of the input string only, without reference to the artifact table. |
| 68 | 68 | */ |
| 69 | 69 | char *fossil_expand_datetime(const char *zIn, int bVerifyNotAHash){ |
| 70 | - static char zEDate[20]; | |
| 70 | + static char zEDate[24]; | |
| 71 | 71 | static const char aPunct[] = { 0, 0, '-', '-', ' ', ':', ':' }; |
| 72 | 72 | int n = (int)strlen(zIn); |
| 73 | 73 | int i, j; |
| 74 | + int addZulu = 0; | |
| 74 | 75 | |
| 75 | - /* Only three forms allowed: | |
| 76 | + /* These forms are allowed: | |
| 77 | + ** | |
| 76 | 78 | ** (1) YYYYMMDD |
| 77 | 79 | ** (2) YYYYMMDDHHMM |
| 78 | 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. | |
| 79 | 84 | */ |
| 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 | + } | |
| 81 | 93 | |
| 82 | 94 | /* Every character must be a digit */ |
| 83 | 95 | for(i=0; fossil_isdigit(zIn[i]); i++){} |
| 84 | - if( i!=n ) return 0; | |
| 96 | + if( i!=n && (!addZulu || i!=n+1) ) return 0; | |
| 85 | 97 | |
| 86 | 98 | /* Expand the date */ |
| 87 | - for(i=j=0; zIn[i]; i++){ | |
| 99 | + for(i=j=0; i<n; i++){ | |
| 88 | 100 | if( i>=4 && (i%2)==0 ){ |
| 89 | 101 | zEDate[j++] = aPunct[i/2]; |
| 90 | 102 | } |
| 91 | 103 | zEDate[j++] = zIn[i]; |
| 92 | 104 | } |
| 105 | + if( addZulu ) zEDate[j++] = 'Z'; | |
| 93 | 106 | zEDate[j] = 0; |
| 94 | 107 | |
| 95 | 108 | /* Check for reasonable date values. |
| 96 | 109 | ** Offset references: |
| 97 | 110 | ** YYYY-MM-DD HH:MM:SS |
| @@ -111,11 +124,11 @@ | ||
| 111 | 124 | if( i>60 ) return 0; |
| 112 | 125 | if( n==14 && atoi(zEDate+17)>60 ) return 0; |
| 113 | 126 | } |
| 114 | 127 | |
| 115 | 128 | /* The string is not also a hash prefix */ |
| 116 | - if( bVerifyNotAHash ){ | |
| 129 | + if( bVerifyNotAHash && !addZulu ){ | |
| 117 | 130 | if( db_exists("SELECT 1 FROM blob WHERE uuid GLOB '%q*'",zIn) ) return 0; |
| 118 | 131 | } |
| 119 | 132 | |
| 120 | 133 | /* It looks like this may be a date. Return it with punctuation added. */ |
| 121 | 134 | return zEDate; |
| 122 | 135 |
| --- 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 |