]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
The %W date specifier in strftime should be measured from the first Monday
authordrh <drh@noemail.net>
Sun, 18 Jul 2004 22:25:15 +0000 (22:25 +0000)
committerdrh <drh@noemail.net>
Sun, 18 Jul 2004 22:25:15 +0000 (22:25 +0000)
of the year.  Ticket #758. (CVS 1806)

FossilOrigin-Name: 135e5447f66fcd8ec4350c81707a2e8d3c9fd31c

manifest
manifest.uuid
src/date.c
test/date.test

index 6b7d953ac489d04d3e3a06d179e95f38d6622515..a0592584960f477a6df8ceeb4d1ef0be4480fca2 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Min()\sand\smax()\signore\sNULL\svalues.\s\sTicket\s#800.\s(CVS\s1803)
-D 2004-07-18T21:14:05
+C The\s%W\sdate\sspecifier\sin\sstrftime\sshould\sbe\smeasured\sfrom\sthe\sfirst\sMonday\nof\sthe\syear.\s\sTicket\s#758.\s(CVS\s1806)
+D 2004-07-18T22:25:15
 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -28,7 +28,7 @@ F src/btree.h 41cb3ff6ebc3f6da2d0a074e39ff8c7a2287469f
 F src/btree_rb.c af40501eedd7b673ffd5e02f3a4702c76596d64a
 F src/build.c cb1ab5ce737ae6b6fe141e256c5e7c524c78ed68
 F src/copy.c 750e13828c3e4a293123e36aaa7cf0f22466248a
-F src/date.c f055419d602bde622c70f831350b6b52f2235de0
+F src/date.c 6ccb9336f1faef639d52b0aa4d31244d665607fa
 F src/delete.c 82001c74882319f94dab5f6b92a27311b31092ae
 F src/encode.c fc8c51f0b61bc803ccdec092e130bebe762b0a2f
 F src/expr.c 8c3f5603c3e98b1c146d18076ba3e82cdbb59c11
@@ -83,7 +83,7 @@ F test/capi2.test ec96e0e235d87b53cbaef3d8e3e0f8ccf32c71ca
 F test/conflict.test 0911bb2f079046914a6e9c3341b36658c4e2103e
 F test/copy.test f07ea8d60878da7a67416ab62f78e9706b9d3c45
 F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
-F test/date.test aed5030482ebc02bd8d386c6c86a29f694ab068d
+F test/date.test aa4bc2aae379bed3f838ea73de0cde1c352c5545
 F test/delete.test 92256384f1801760180ded129f7427884cf28886
 F test/expr.test ad985242e140f87eeef329d98257b8369a2066dc
 F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
@@ -189,7 +189,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
 F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P ea364dffc7dfe7533d6916d63db0a79181440e64
-R 8bd46754e3600088dd9144cc11814695
+P 223521c04e8ad39e06fee455f7dbb31ace2d3800
+R 2162cd7e88b845d13ee12e77797aa720
 U drh
-Z 90af30adbb2fcd99b6ec0617557df19e
+Z 5dc138bdcbb1d569eebdca901b4f37d0
index bbbdeaa91f73d3154a47bb377289914be6a82ac2..2f589e2735429316d7c8246af0f8363c9c3e5c9b 100644 (file)
@@ -1 +1 @@
-223521c04e8ad39e06fee455f7dbb31ace2d3800
\ No newline at end of file
+135e5447f66fcd8ec4350c81707a2e8d3c9fd31c
\ No newline at end of file
index 03b66add9e20900ae1c403261cf61766c8169a82..418cce52d2bcf2bedded48be00463b7802967695 100644 (file)
@@ -16,7 +16,7 @@
 ** sqliteRegisterDateTimeFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: date.c,v 1.16 2004/02/29 01:08:18 drh Exp $
+** $Id: date.c,v 1.16.2.1 2004/07/18 22:25:15 drh Exp $
 **
 ** NOTES:
 **
@@ -800,18 +800,20 @@ static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
         case 'H':  sprintf(&z[j],"%02d",x.h); j+=2; break;
         case 'W': /* Fall thru */
         case 'j': {
-          int n;
+          int n;             /* Number of days since 1st day of year */
           DateTime y = x;
           y.validJD = 0;
           y.M = 1;
           y.D = 1;
           computeJD(&y);
-          n = x.rJD - y.rJD + 1;
+          n = x.rJD - y.rJD;
           if( zFmt[i]=='W' ){
-            sprintf(&z[j],"%02d",(n+6)/7);
+            int wd;   /* 0=Monday, 1=Tuesday, ... 6=Sunday */
+            wd = ((int)(x.rJD+0.5)) % 7;
+            sprintf(&z[j],"%02d",(n+7-wd)/7);
             j += 2;
           }else{
-            sprintf(&z[j],"%03d",n);
+            sprintf(&z[j],"%03d",n+1);
             j += 3;
           }
           break;
index 041a4f6c5ed0db0f83c3b584f07ed691467425a1..5ef90d19de40cd7dd856f9b3ef30a81360412685 100644 (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.7 2004/02/29 01:08:18 drh Exp $
+# $Id: date.test,v 1.7.2.1 2004/07/18 22:25:16 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -95,7 +95,20 @@ datetest 3.7 {strftime('%M','2003-10-31 12:34:56.432')} 34
 datetest 3.8 {strftime('%s','2003-10-31 12:34:56.432')} 1067603696
 datetest 3.9 {strftime('%S','2003-10-31 12:34:56.432')} 56
 datetest 3.10 {strftime('%w','2003-10-31 12:34:56.432')} 5
-datetest 3.11 {strftime('%W','2003-10-31 12:34:56.432')} 44
+datetest 3.11.1 {strftime('%W','2003-10-31 12:34:56.432')} 43
+datetest 3.11.2 {strftime('%W','2004-01-01')} 00
+datetest 3.11.3 {strftime('%W','2004-01-02')} 00
+datetest 3.11.4 {strftime('%W','2004-01-03')} 00
+datetest 3.11.5 {strftime('%W','2004-01-04')} 00
+datetest 3.11.6 {strftime('%W','2004-01-05')} 01
+datetest 3.11.7 {strftime('%W','2004-01-06')} 01
+datetest 3.11.8 {strftime('%W','2004-01-07')} 01
+datetest 3.11.9 {strftime('%W','2004-01-08')} 01
+datetest 3.11.10 {strftime('%W','2004-01-09')} 01
+datetest 3.11.11 {strftime('%W','2004-07-18')} 28
+datetest 3.11.12 {strftime('%W','2004-12-31')} 52
+datetest 3.11.13 {strftime('%W','2007-12-31')} 53
+datetest 3.11.14 {strftime('%W','2007-01-01')} 01
 datetest 3.12 {strftime('%Y','2003-10-31 12:34:56.432')} 2003
 datetest 3.13 {strftime('%%','2003-10-31 12:34:56.432')} %
 datetest 3.14 {strftime('%_','2003-10-31 12:34:56.432')} NULL