mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Enhance date/time functions to work with negative years. Ticket #617. (CVS 1255)
FossilOrigin-Name: ffa971934867b6bbe943c004154d5f161e0ea697
This commit is contained in:
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
|||||||
C Turn\sthe\sshort_column_names\spragma\soff\sby\sdefault\s-\sfor\sthe\stime\sbeing.\s(CVS\s1254)
|
C Enhance\sdate/time\sfunctions\sto\swork\swith\snegative\syears.\s\sTicket\s#617.\s(CVS\s1255)
|
||||||
D 2004-02-20T23:34:07
|
D 2004-02-21T03:28:18
|
||||||
F Makefile.in cfd75c46b335881999333a9e4b982fa8491f200b
|
F Makefile.in cfd75c46b335881999333a9e4b982fa8491f200b
|
||||||
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
||||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||||
@ -29,7 +29,7 @@ F src/btree.h 41cb3ff6ebc3f6da2d0a074e39ff8c7a2287469f
|
|||||||
F src/btree_rb.c 32b2cb4285c0fbd53b89de021637b63d52257e54
|
F src/btree_rb.c 32b2cb4285c0fbd53b89de021637b63d52257e54
|
||||||
F src/build.c e6d71a3babd1f523abdd806555be3430adbd69eb
|
F src/build.c e6d71a3babd1f523abdd806555be3430adbd69eb
|
||||||
F src/copy.c 391ce142f6b1faa093867ecee134f61a5028a9af
|
F src/copy.c 391ce142f6b1faa093867ecee134f61a5028a9af
|
||||||
F src/date.c c9d2bfd40b1c95f8f97d53a5eba981d7167c7b61
|
F src/date.c 6120c591cd905799318018cc67df53e9bdfaef28
|
||||||
F src/delete.c 8e2ff752bf485906effcc64f267cdd7227463567
|
F src/delete.c 8e2ff752bf485906effcc64f267cdd7227463567
|
||||||
F src/encode.c 9e70ea1e4e746f23f18180949e94f1bb1c2220d3
|
F src/encode.c 9e70ea1e4e746f23f18180949e94f1bb1c2220d3
|
||||||
F src/expr.c fdd57e18cf6f2dea42e1e1930930b32ec6351c47
|
F src/expr.c fdd57e18cf6f2dea42e1e1930930b32ec6351c47
|
||||||
@ -84,7 +84,7 @@ F test/capi2.test ec96e0e235d87b53cbaef3d8e3e0f8ccf32c71ca
|
|||||||
F test/conflict.test 0911bb2f079046914a6e9c3341b36658c4e2103e
|
F test/conflict.test 0911bb2f079046914a6e9c3341b36658c4e2103e
|
||||||
F test/copy.test f07ea8d60878da7a67416ab62f78e9706b9d3c45
|
F test/copy.test f07ea8d60878da7a67416ab62f78e9706b9d3c45
|
||||||
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
|
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
|
||||||
F test/date.test bb3ce39211cc6687a187133efeb2066b48993643
|
F test/date.test 80cc84210b59af26e03ffa3f323bdeb5190a48dd
|
||||||
F test/delete.test 92256384f1801760180ded129f7427884cf28886
|
F test/delete.test 92256384f1801760180ded129f7427884cf28886
|
||||||
F test/expr.test c4cc292d601019c2f2ce95093caaa5d10284b105
|
F test/expr.test c4cc292d601019c2f2ce95093caaa5d10284b105
|
||||||
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
|
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
|
||||||
@ -189,7 +189,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
|
|||||||
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
|
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
|
||||||
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
|
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
|
||||||
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
|
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
|
||||||
P b1b23c410260293f57614f32232cf1276f41c16b
|
P 6954d2c3240459842be655b600c6b160e918e74a
|
||||||
R a77bad2f0fdb5f58fdc86ec241aff60d
|
R 3b2fc592a58487f152d3f08ba1a44ce5
|
||||||
U drh
|
U drh
|
||||||
Z 99f24ada72efe423c099a6c6ffecaab2
|
Z 27734a3b760ca8def8dc98b0f2f23cfc
|
||||||
|
@ -1 +1 @@
|
|||||||
6954d2c3240459842be655b600c6b160e918e74a
|
ffa971934867b6bbe943c004154d5f161e0ea697
|
23
src/date.c
23
src/date.c
@ -16,7 +16,7 @@
|
|||||||
** sqliteRegisterDateTimeFunctions() found at the bottom of the file.
|
** sqliteRegisterDateTimeFunctions() found at the bottom of the file.
|
||||||
** All other code has file scope.
|
** All other code has file scope.
|
||||||
**
|
**
|
||||||
** $Id: date.c,v 1.10 2004/02/10 13:19:35 drh Exp $
|
** $Id: date.c,v 1.11 2004/02/21 03:28:18 drh Exp $
|
||||||
**
|
**
|
||||||
** NOTES:
|
** NOTES:
|
||||||
**
|
**
|
||||||
@ -260,8 +260,14 @@ static void computeJD(DateTime *p){
|
|||||||
** date.
|
** date.
|
||||||
*/
|
*/
|
||||||
static int parseYyyyMmDd(const char *zDate, DateTime *p){
|
static int parseYyyyMmDd(const char *zDate, DateTime *p){
|
||||||
int Y, M, D;
|
int Y, M, D, neg;
|
||||||
|
|
||||||
|
if( zDate[0]=='-' ){
|
||||||
|
zDate++;
|
||||||
|
neg = 1;
|
||||||
|
}else{
|
||||||
|
neg = 0;
|
||||||
|
}
|
||||||
Y = getDigits(zDate, 4);
|
Y = getDigits(zDate, 4);
|
||||||
if( Y<0 || zDate[4]!='-' ) return 1;
|
if( Y<0 || zDate[4]!='-' ) return 1;
|
||||||
zDate += 5;
|
zDate += 5;
|
||||||
@ -281,7 +287,7 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
|
|||||||
}
|
}
|
||||||
p->validJD = 0;
|
p->validJD = 0;
|
||||||
p->validYMD = 1;
|
p->validYMD = 1;
|
||||||
p->Y = Y;
|
p->Y = neg ? -Y : Y;
|
||||||
p->M = M;
|
p->M = M;
|
||||||
p->D = D;
|
p->D = D;
|
||||||
if( p->validTZ ){
|
if( p->validTZ ){
|
||||||
@ -307,15 +313,12 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
|
|||||||
** as there is a year and date.
|
** as there is a year and date.
|
||||||
*/
|
*/
|
||||||
static int parseDateOrTime(const char *zDate, DateTime *p){
|
static int parseDateOrTime(const char *zDate, DateTime *p){
|
||||||
int i;
|
|
||||||
memset(p, 0, sizeof(*p));
|
memset(p, 0, sizeof(*p));
|
||||||
for(i=0; isdigit(zDate[i]); i++){}
|
if( parseYyyyMmDd(zDate,p)==0 ){
|
||||||
if( i==4 && zDate[i]=='-' ){
|
|
||||||
return parseYyyyMmDd(zDate, p);
|
|
||||||
}else if( i==2 && zDate[i]==':' ){
|
|
||||||
return parseHhMmSs(zDate, p);
|
|
||||||
return 0;
|
return 0;
|
||||||
}else if( i==0 && sqliteStrICmp(zDate,"now")==0 ){
|
}else if( parseHhMmSs(zDate, p)==0 ){
|
||||||
|
return 0;
|
||||||
|
}else if( sqliteStrICmp(zDate,"now")==0){
|
||||||
double r;
|
double r;
|
||||||
if( sqliteOsCurrentTime(&r)==0 ){
|
if( sqliteOsCurrentTime(&r)==0 ){
|
||||||
p->rJD = r;
|
p->rJD = r;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# This file implements regression tests for SQLite library. The
|
# This file implements regression tests for SQLite library. The
|
||||||
# focus of this file is testing date and time functions.
|
# focus of this file is testing date and time functions.
|
||||||
#
|
#
|
||||||
# $Id: date.test,v 1.5 2004/01/07 03:29:16 drh Exp $
|
# $Id: date.test,v 1.6 2004/02/21 03:28:18 drh Exp $
|
||||||
|
|
||||||
set testdir [file dirname $argv0]
|
set testdir [file dirname $argv0]
|
||||||
source $testdir/tester.tcl
|
source $testdir/tester.tcl
|
||||||
@ -201,5 +201,15 @@ datetest 8.18 {datetime('now','-1.25 hours')} {2003-10-22 11:19:00}
|
|||||||
datetest 8.19 {datetime('now','11.25 seconds')} {2003-10-22 12:34:11}
|
datetest 8.19 {datetime('now','11.25 seconds')} {2003-10-22 12:34:11}
|
||||||
set sqlite_current_time 0
|
set sqlite_current_time 0
|
||||||
|
|
||||||
|
# Negative years work. Example: '-4713-11-26' is JD 1.5.
|
||||||
|
#
|
||||||
|
datetest 9.1 {julianday('-4713-11-24 12:00:00')} {0}
|
||||||
|
datetest 9.2 {julianday(datetime(5))} {5}
|
||||||
|
datetest 9.3 {julianday(datetime(10))} {10}
|
||||||
|
datetest 9.4 {julianday(datetime(100))} {100}
|
||||||
|
datetest 9.5 {julianday(datetime(1000))} {1000}
|
||||||
|
datetest 9.6 {julianday(datetime(10000))} {10000}
|
||||||
|
datetest 9.7 {julianday(datetime(100000))} {100000}
|
||||||
|
|
||||||
|
|
||||||
finish_test
|
finish_test
|
||||||
|
Reference in New Issue
Block a user