SQLite

Check-in [1218005ab7]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:More improvements to boundary cases in the date/time functions, flowing out of branch coverage testing.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1218005ab7b52ef45db1354d17fdd8a1a1af9854
User & Date: drh 2016-11-30 04:07:57.427
Context
2016-11-30
05:08
Change the OP_DecrJumpZero opcode back to its old behavior of always decrementing, except top the decrementing when it reaches the largest negative number. (check-in: 9d0d8c2e7c user: drh tags: trunk)
04:07
More improvements to boundary cases in the date/time functions, flowing out of branch coverage testing. (check-in: 1218005ab7 user: drh tags: trunk)
01:05
Prevent a warning about integer overflow when using a very large negative LIMIT. (check-in: 96106d5620 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/date.c.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#endif

/*
** A structure for holding a single date and time.
*/
typedef struct DateTime DateTime;
struct DateTime {
  sqlite3_uint64 iJD; /* The julian day number times 86400000 */
  int Y, M, D;        /* Year, month, and day */
  int h, m;           /* Hour and minutes */
  int tz;             /* Timezone offset in minutes */
  double s;           /* Seconds */
  char validYMD;      /* True (1) if Y,M,D are valid */
  char validHMS;      /* True (1) if h,m,s are valid */
  char validJD;       /* True (1) if iJD is valid */







|







61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#endif

/*
** A structure for holding a single date and time.
*/
typedef struct DateTime DateTime;
struct DateTime {
  sqlite3_int64 iJD;  /* The julian day number times 86400000 */
  int Y, M, D;        /* Year, month, and day */
  int h, m;           /* Hour and minutes */
  int tz;             /* Timezone offset in minutes */
  double s;           /* Seconds */
  char validYMD;      /* True (1) if Y,M,D are valid */
  char validHMS;      /* True (1) if h,m,s are valid */
  char validJD;       /* True (1) if iJD is valid */
825
826
827
828
829
830
831


832
833
834
835
836
837
838
839
840
841
842
843

844
845
846
847
848
849
850
851
  int eType;
  memset(p, 0, sizeof(*p));
  if( argc==0 ){
    return setDateTimeToCurrent(context, p);
  }
  if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
                   || eType==SQLITE_INTEGER ){


    p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
    p->validJD = 1;
  }else{
    z = sqlite3_value_text(argv[0]);
    if( !z || parseDateOrTime(context, (char*)z, p) ){
      return 1;
    }
  }
  for(i=1; i<argc; i++){
    z = sqlite3_value_text(argv[i]);
    if( z==0 || parseModifier(context, (char*)z, p) ) return 1;
  }

  if( p->isError || (p->validJD && !validJulianDay(p->iJD)) ) return 1;
  return 0;
}


/*
** The following routines implement the various date and time functions
** of SQLite.







>
>
|











>
|







825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
  int eType;
  memset(p, 0, sizeof(*p));
  if( argc==0 ){
    return setDateTimeToCurrent(context, p);
  }
  if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
                   || eType==SQLITE_INTEGER ){
    double r = sqlite3_value_double(argv[0]);
    if( r>106751991167.0 || r<-106751991167.0 ) return 1;
    p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
    p->validJD = 1;
  }else{
    z = sqlite3_value_text(argv[0]);
    if( !z || parseDateOrTime(context, (char*)z, p) ){
      return 1;
    }
  }
  for(i=1; i<argc; i++){
    z = sqlite3_value_text(argv[i]);
    if( z==0 || parseModifier(context, (char*)z, p) ) return 1;
  }
  computeJD(p);
  if( p->isError || !validJulianDay(p->iJD) ) return 1;
  return 0;
}


/*
** The following routines implement the various date and time functions
** of SQLite.