Re: Datetime patch

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: greg(at)turnstep(dot)com
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Datetime patch
Date: 2003-07-25 14:55:46
Message-ID: 200307251455.h6PEtkW16894@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches


Greg, does this patch still reject dates with month/days out of range?
I see some of the range checks are removed. Where those checks used
only for the month/date detection?

For example, I don't see the <= 31 checks in there anymore.

---------------------------------------------------------------------------

greg(at)turnstep(dot)com wrote:
[ There is text before PGP section. ]
>
[ PGP not available, raw data follows ]
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> NotDashEscaped: You need GnuPG to verify this message
>
>
> > I believe this conditional is incorrect. The second part should be DTK_M(DAY).
>
> Thank you - that is correct. Revised patch below.
>
>
>
>
> Index: datetime.c
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/datetime.c,v
> retrieving revision 1.106
> diff -c -r1.106 datetime.c
> *** datetime.c 25 Jun 2003 21:14:14 -0000 1.106
> --- datetime.c 30 Jun 2003 17:26:22 -0000
> ***************
> *** 2379,2440 ****
> ***/
> else if (flen >= 4)
> {
> ! *tmask = DTK_M(YEAR);
>
> ! /* already have a year? then see if we can substitute... */
> ! if ((fmask & DTK_M(YEAR)) && (!(fmask & DTK_M(DAY)))
> ! && ((tm->tm_year >= 1) && (tm->tm_year <= 31)))
> {
> ! tm->tm_mday = tm->tm_year;
> ! *tmask = DTK_M(DAY);
> }
> !
> ! tm->tm_year = val;
> }
> !
> ! /* already have year? then could be month */
> ! else if ((fmask & DTK_M(YEAR)) && (!(fmask & DTK_M(MONTH)))
> ! && ((val >= 1) && (val <= 12)))
> {
> ! *tmask = DTK_M(MONTH);
> ! tm->tm_mon = val;
> }
> ! /* no year and EuroDates enabled? then could be day */
> ! else if ((EuroDates || (fmask & DTK_M(MONTH)))
> ! && (!(fmask & DTK_M(YEAR)) && !(fmask & DTK_M(DAY)))
> ! && ((val >= 1) && (val <= 31)))
> {
> *tmask = DTK_M(DAY);
> tm->tm_mday = val;
> }
> ! else if ((!(fmask & DTK_M(MONTH)))
> ! && ((val >= 1) && (val <= 12)))
> {
> *tmask = DTK_M(MONTH);
> tm->tm_mon = val;
> }
> ! else if ((!(fmask & DTK_M(DAY)))
> ! && ((val >= 1) && (val <= 31)))
> {
> *tmask = DTK_M(DAY);
> tm->tm_mday = val;
> }
> !
> ! /*
> ! * Check for 2 or 4 or more digits, but currently we reach here only
> ! * if two digits. - thomas 2000-03-28
> ! */
> ! else if (!(fmask & DTK_M(YEAR))
> ! && ((flen >= 4) || (flen == 2)))
> {
> ! *tmask = DTK_M(YEAR);
> ! tm->tm_year = val;
> !
> ! /* adjust ONLY if exactly two digits... */
> ! *is2digits = (flen == 2);
> }
> else
> ! return -1;
>
> return 0;
> } /* DecodeNumber() */
> --- 2379,2447 ----
> ***/
> else if (flen >= 4)
> {
> ! /*
> ! * If no month or day, start of YYYY-MM-DD
> ! * If have month AND day, end of MM-DD-YYYY or DD-MM-YYYY
> ! * If neither case, throw an error
> ! */
>
> ! if ((!(fmask & DTK_M(YEAR)))
> ! && (((!(fmask & DTK_M(DAY))) && (!(fmask & DTK_M(MONTH))))
> ! ||
> ! ((fmask & DTK_M(DAY)) && (fmask & DTK_M(MONTH)))))
> {
> ! *tmask = DTK_M(YEAR);
> ! tm->tm_year = val;
> }
> ! else
> ! return -1;
> }
> ! /* If we already have a day AND month, must be a 2-digit year */
> ! else if ((fmask & DTK_M(DAY)) && (fmask & DTK_M(MONTH)))
> {
> ! *tmask = DTK_M(YEAR);
> ! tm->tm_year = val;
> ! *is2digits = TRUE;
> }
> !
> ! /* If we already have a year and a month, must be day */
> ! else if ((fmask & DTK_M(YEAR)) && (fmask & DTK_M(MONTH)))
> {
> *tmask = DTK_M(DAY);
> tm->tm_mday = val;
> }
> ! /* A year and a day is currently an error, as YYYY-DD-MM is not allowed */
> ! else if ((fmask & DTK_M(YEAR)) && (fmask & DTK_M(DAY)))
> ! return -1;
> ! /* If have year or day, set the month */
> ! else if ((fmask & DTK_M(YEAR)) || (fmask & DTK_M(DAY)))
> {
> + /* Do not allow month to roll over */
> + if (val > 12)
> + return -1;
> *tmask = DTK_M(MONTH);
> tm->tm_mon = val;
> }
> ! /* If have a month, set the day */
> ! else if ((fmask & DTK_M(MONTH)))
> {
> *tmask = DTK_M(DAY);
> tm->tm_mday = val;
> }
> ! /* If using EuroDates, this must be the day, otherwise month */
> ! else if (EuroDates)
> {
> ! *tmask = DTK_M(DAY);
> ! tm->tm_mday = val;
> }
> else
> ! {
> ! /* Do not allow month to roll over */
> ! if (val > 12)
> ! return -1;
> ! *tmask = DTK_M(MONTH);
> ! tm->tm_mon = val;-----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> NotDashEscaped: You need GnuPG to verify this message
>
>
> > I believe this conditional is incorrect. The second part should be DTK_M(DAY).
>
> Thank you - that is correct. Revised patch below.
>
>
>
>
> Index: datetime.c
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/datetime.c,v
> retrieving revision 1.106
> diff -c -r1.106 datetime.c
> *** datetime.c 25 Jun 2003 21:14:14 -0000 1.106
> --- datetime.c 30 Jun 2003 17:26:22 -0000
> ***************
> *** 2379,2440 ****
> ***/
> else if (flen >= 4)
> {
> ! *tmask = DTK_M(YEAR);
>
> ! /* already have a year? then see if we can substitute... */
> ! if ((fmask & DTK_M(YEAR)) && (!(fmask & DTK_M(DAY)))
> ! && ((tm->tm_year >= 1) && (tm->tm_year <= 31)))
> {
> ! tm->tm_mday = tm->tm_year;
> ! *tmask = DTK_M(DAY);
> }
> !
> ! tm->tm_year = val;
> }
> !
> ! /* already have year? then could be month */
> ! else if ((fmask & DTK_M(YEAR)) && (!(fmask & DTK_M(MONTH)))
> ! && ((val >= 1) && (val <= 12)))
> {
> ! *tmask = DTK_M(MONTH);
> ! tm->tm_mon = val;
> }
> ! /* no year and EuroDates enabled? then could be day */
> ! else if ((EuroDates || (fmask & DTK_M(MONTH)))
> ! && (!(fmask & DTK_M(YEAR)) && !(fmask & DTK_M(DAY)))
> ! && ((val >= 1) && (val <= 31)))
> {
> *tmask = DTK_M(DAY);
> tm->tm_mday = val;
> }
> ! else if ((!(fmask & DTK_M(MONTH)))
> ! && ((val >= 1) && (val <= 12)))
> {
> *tmask = DTK_M(MONTH);
> tm->tm_mon = val;
> }
> ! else if ((!(fmask & DTK_M(DAY)))
> ! && ((val >= 1) && (val <= 31)))
> {
> *tmask = DTK_M(DAY);
> tm->tm_mday = val;
> }
> !
> ! /*
> ! * Check for 2 or 4 or more digits, but currently we reach here only
> ! * if two digits. - thomas 2000-03-28
> ! */
> ! else if (!(fmask & DTK_M(YEAR))
> ! && ((flen >= 4) || (flen == 2)))
> {
> ! *tmask = DTK_M(YEAR);
> ! tm->tm_year = val;
> !
> ! /* adjust ONLY if exactly two digits... */
> ! *is2digits = (flen == 2);
> }
> else
> ! return -1;
>
> return 0;
> } /* DecodeNumber() */
> --- 2379,2447 ----
> ***/
> else if (flen >= 4)
> {
> ! /*
> ! * If no month or day, start of YYYY-MM-DD
> ! * If have month AND day, end of MM-DD-YYYY or DD-MM-YYYY
> ! * If neither case, throw an error
> ! */
>
> ! if ((!(fmask & DTK_M(YEAR)))
> ! && (((!(fmask & DTK_M(DAY))) && (!(fmask & DTK_M(MONTH))))
> ! ||
> ! ((fmask & DTK_M(DAY)) && (fmask & DTK_M(MONTH)))))
> {
> ! *tmask = DTK_M(YEAR);
> ! tm->tm_year = val;
> }
> ! else
> ! return -1;
> }
> ! /* If we already have a day AND month, must be a 2-digit year */
> ! else if ((fmask & DTK_M(DAY)) && (fmask & DTK_M(MONTH)))
> {
> ! *tmask = DTK_M(YEAR);
> ! tm->tm_year = val;
> ! *is2digits = TRUE;
> }
> !
> ! /* If we already have a year and a month, must be day */
> ! else if ((fmask & DTK_M(YEAR)) && (fmask & DTK_M(MONTH)))
> {
> *tmask = DTK_M(DAY);
> tm->tm_mday = val;
> }
> ! /* A year and a day is currently an error, as YYYY-DD-MM is not allowed */
> ! else if ((fmask & DTK_M(YEAR)) && (fmask & DTK_M(DAY)))
> ! return -1;
> ! /* If have year or day, set the month */
> ! else if ((fmask & DTK_M(YEAR)) || (fmask & DTK_M(DAY)))
> {
> + /* Do not allow month to roll over */
> + if (val > 12)
> + return -1;
> *tmask = DTK_M(MONTH);
> tm->tm_mon = val;
> }
> ! /* If have a month, set the day */
> ! else if ((fmask & DTK_M(MONTH)))
> {
> *tmask = DTK_M(DAY);
> tm->tm_mday = val;
> }
> ! /* If using EuroDates, this must be the day, otherwise month */
> ! else if (EuroDates)
> {
> ! *tmask = DTK_M(DAY);
> ! tm->tm_mday = val;
> }
> else
> ! {
> ! /* Do not allow month to roll over */
> ! if (val > 12)
> ! return -1;
> ! *tmask = DTK_M(MONTH);
> ! tm->tm_mon = val;
> ! }
>
> return 0;
> } /* DecodeNumber() */
>
>
>
>
>
> --
> Greg Sabino Mullane greg(at)turnstep(dot)com
> PGP Key: 0x14964AC8 200307010916
> -----BEGIN PGP SIGNATURE-----
> Comment: http://www.turnstep.com/pgp.html
>
> iD8DBQE/AYp/vJuQZxSWSsgRAvaLAKCG9si7HhJLOnVIbhPKCo/bP6HMOACfRtlq
> DivxA+RBcivkseNS/yvzc/0=
> =mris
> -----END PGP SIGNATURE-----
>
> ! }
>
> return 0;
> } /* DecodeNumber() */
>
>
>
>
>
> --
> Greg Sabino Mullane greg(at)turnstep(dot)com
> PGP Key: 0x14964AC8 200307010916
> -----BEGIN PGP SIGNATURE-----
> Comment: http://www.turnstep.com/pgp.html
>
> iD8DBQE/AYp/vJuQZxSWSsgRAvaLAKCG9si7HhJLOnVIbhPKCo/bP6HMOACfRtlq
> DivxA+RBcivkseNS/yvzc/0=
> =mris
> -----END PGP SIGNATURE-----
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>
[ Decrypting message... End of raw data. ]

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2003-07-25 15:02:58 Re: flex 2.5.31
Previous Message Tom Lane 2003-07-25 14:53:53 Re: v7.3.4 bundled ...

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2003-07-25 14:59:31 Re: UPDATED Patch for adding DATACUBE operator
Previous Message Larry Rosenman 2003-07-25 12:57:38 Re: PG Patch (fwd) [openserver patch followup #2]