Preserve the HH:MM:SS for most date/time modifiers. Ticket #551. (CVS 1163)

FossilOrigin-Name: 70df32b716b0d6a4f72bb3ae6496431e53733b6a
This commit is contained in:
drh 2004-01-07 03:29:16 +00:00
parent 384eef32fd
commit c5dd9fa8ab
4 changed files with 48 additions and 17 deletions

View File

@ -1,5 +1,5 @@
C Use\s"long\sdouble"\sto\shold\sintermediate\svalues\swhen\sdoing\sascii\sto\sbinary\nand\sbinary\sto\sascii\sconversions\sof\sfloating\spoint\snumbers.\s(CVS\s1162)
D 2004-01-07T03:04:27
C Preserve\sthe\sHH:MM:SS\sfor\smost\sdate/time\smodifiers.\s\sTicket\s#551.\s(CVS\s1163)
D 2004-01-07T03:29:16
F Makefile.in 0515ff9218ad8d5a8f6220f0494b8ef94c67013b
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@ -28,7 +28,7 @@ F src/btree.h 9b7c09f1e64274d7bb74a57bbfc63778f67b1048
F src/btree_rb.c e4084b6a12270674b0cd7034655f55e6a2639c78
F src/build.c a7493c433de5b552f9535d8fa7ed80aaf135491e
F src/copy.c 9e47975ea96751c658bcf1a0c4f0bb7c6ee61e73
F src/date.c 13775c2dedfc805ebf3f6507bad676f7c974a241
F src/date.c eef0ccd9d0b1d9fe74ed2ae8e247578be3f49bc4
F src/delete.c 0f81e6799c089487615d38e042a2de4d2d6192bc
F src/encode.c 25ea901a9cefb3d93774afa4a06b57cb58acf544
F src/expr.c abb40922fa9995aca06f999ed35d2061d44650d6
@ -84,7 +84,7 @@ F test/btree4rb.test ae6f0438512edcb45cf483471cd6070a765963a9
F test/capi2.test ec96e0e235d87b53cbaef3d8e3e0f8ccf32c71ca
F test/conflict.test 0911bb2f079046914a6e9c3341b36658c4e2103e
F test/copy.test 88dabd4e811b17644b726aa81d404e73b7635c84
F test/date.test 4ef4cfd6aeed10085de8e6872c6b50a534a76979
F test/date.test bb3ce39211cc6687a187133efeb2066b48993643
F test/delete.test 92256384f1801760180ded129f7427884cf28886
F test/expr.test c4cc292d601019c2f2ce95093caaa5d10284b105
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
@ -179,7 +179,7 @@ F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3
F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
P 4146f8cc3ff5339b5685e9c5121888ae08ee0807
R a72185418e2bb2fb61e2933a561c40a9
P 8371f662d22be0a3c58e0503c7511faea1640955
R 9beb2865d5ca7294516b220b6efbaf89
U drh
Z b12256f36463d2cff38d7ba61f10330a
Z 2e358c90c9fe078d5ac1cc696a8654f1

View File

@ -1 +1 @@
8371f662d22be0a3c58e0503c7511faea1640955
70df32b716b0d6a4f72bb3ae6496431e53733b6a

View File

@ -16,7 +16,7 @@
** sqliteRegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: date.c,v 1.6 2003/12/31 17:25:48 drh Exp $
** $Id: date.c,v 1.7 2004/01/07 03:29:16 drh Exp $
**
** NOTES:
**
@ -494,16 +494,15 @@ static int parseModifier(const char *zMod, DateTime *p){
/*
** weekday N
**
** Move the date to the beginning of the next occurrance of
** Move the date to the same time on the next occurrance of
** weekday N where 0==Sunday, 1==Monday, and so forth. If the
** date is already on the appropriate weekday, this is equivalent
** to "start of day".
** date is already on the appropriate weekday, this is a no-op.
*/
if( strncmp(z, "weekday ", 8)==0 && getValue(&z[8],&r)>0
&& (n=r)==r && n>=0 && r<7 ){
int Z;
computeYMD(p);
p->validHMS = 0;
computeHMS(p);
p->validTZ = 0;
p->validJD = 0;
computeJD(p);
@ -581,6 +580,7 @@ static int parseModifier(const char *zMod, DateTime *p){
}else if( n==5 && strcmp(z,"month")==0 ){
int x, y;
computeYMD(p);
computeHMS(p);
p->M += r;
x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
p->Y += x;
@ -593,6 +593,7 @@ static int parseModifier(const char *zMod, DateTime *p){
}
}else if( n==4 && strcmp(z,"year")==0 ){
computeYMD(p);
computeHMS(p);
p->Y += r;
p->validJD = 0;
computeJD(p);
@ -798,11 +799,11 @@ static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
case 'm': sprintf(&z[j],"%02d",x.M); j+=2; break;
case 'M': sprintf(&z[j],"%02d",x.m); j+=2; break;
case 's': {
sprintf(&z[j],"%d",(int)((x.rJD-2440587.5)*86400.0));
sprintf(&z[j],"%d",(int)((x.rJD-2440587.5)*86400.0 + 0.5));
j += strlen(&z[j]);
break;
}
case 'S': sprintf(&z[j],"%02d",(int)x.s); j+=2; break;
case 'S': sprintf(&z[j],"%02d",(int)(x.s+0.5)); j+=2; break;
case 'w': z[j++] = (((int)(x.rJD+1.5)) % 7) + '0'; break;
case 'Y': sprintf(&z[j],"%04d",x.Y); j+=strlen(&z[j]); break;
case '%': z[j++] = '%'; break;

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing date and time functions.
#
# $Id: date.test,v 1.4 2004/01/02 15:08:43 drh Exp $
# $Id: date.test,v 1.5 2004/01/07 03:29:16 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -59,7 +59,7 @@ datetest 2.8 {date('2003-10-22','weekday 5')} 2003-10-24
datetest 2.9 {date('2003-10-22','weekday 6')} 2003-10-25
datetest 2.10 {date('2003-10-22','weekday 7')} NULL
datetest 2.11 {date('2003-10-22','weekday 5.5')} NULL
datetest 2.12 {datetime('2003-10-22 12:34','weekday 0')} {2003-10-26 00:00:00}
datetest 2.12 {datetime('2003-10-22 12:34','weekday 0')} {2003-10-26 12:34:00}
datetest 2.13 {datetime('2003-10-22 12:34','start of month')} \
{2003-10-01 00:00:00}
datetest 2.14 {datetime('2003-10-22 12:34','start of year')} \
@ -150,6 +150,10 @@ if {[clock scan [clock format 0 -format {%b %d, %Y %H:%M:%S}] -gmt 1]==-18000} {
{1969-07-01 07:00:00}
datetest 6.15 {datetime('2039-07-01 12:00:00','localtime')} \
{2039-07-01 07:00:00}
set sqlite_current_time \
[db eval {SELECT strftime('%s','2000-07-01 12:34:56')}]
datetest 6.16 {datetime('now','localtime')} {2000-07-01 08:34:56}
set sqlite_current_time 0
}
# Date-time functions that contain NULL arguments return a NULL
@ -172,4 +176,30 @@ datetest 7.14 {strftime('%s',null)} NULL
datetest 7.15 {strftime('%s','now',null)} NULL
datetest 7.16 {strftime('%s','now','localtime',null)} NULL
# Test modifiers when the date begins as a julian day number - to
# make sure the HH:MM:SS is preserved. Ticket #551.
#
set sqlite_current_time [db eval {SELECT strftime('%s','2003-10-22 12:34:00')}]
datetest 8.1 {datetime('now','weekday 0')} {2003-10-26 12:34:00}
datetest 8.2 {datetime('now','weekday 1')} {2003-10-27 12:34:00}
datetest 8.3 {datetime('now','weekday 2')} {2003-10-28 12:34:00}
datetest 8.4 {datetime('now','weekday 3')} {2003-10-22 12:34:00}
datetest 8.5 {datetime('now','start of month')} {2003-10-01 00:00:00}
datetest 8.6 {datetime('now','start of year')} {2003-01-01 00:00:00}
datetest 8.7 {datetime('now','start of day')} {2003-10-22 00:00:00}
datetest 8.8 {datetime('now','1 day')} {2003-10-23 12:34:00}
datetest 8.9 {datetime('now','+1 day')} {2003-10-23 12:34:00}
datetest 8.10 {datetime('now','+1.25 day')} {2003-10-23 18:34:00}
datetest 8.11 {datetime('now','-1.0 day')} {2003-10-21 12:34:00}
datetest 8.12 {datetime('now','1 month')} {2003-11-22 12:34:00}
datetest 8.13 {datetime('now','11 month')} {2004-09-22 12:34:00}
datetest 8.14 {datetime('now','-13 month')} {2002-09-22 12:34:00}
datetest 8.15 {datetime('now','1.5 months')} {2003-12-07 12:34:00}
datetest 8.16 {datetime('now','-5 years')} {1998-10-22 12:34:00}
datetest 8.17 {datetime('now','+10.5 minutes')} {2003-10-22 12:44:30}
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}
set sqlite_current_time 0
finish_test