Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9e71660

Browse files
author
Thomas G. Lockhart
committed
Support full POSIX-style time zone: EST+3, PST-3, etc.
We probably support a superset of the spec, but I don't have the spec to confirm this.Update regression tests to include tests for this format.
1 parent90c4bab commit9e71660

File tree

3 files changed

+195
-96
lines changed

3 files changed

+195
-96
lines changed

‎src/backend/utils/adt/datetime.c

Lines changed: 160 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.43 2000/03/14 23:06:36 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.44 2000/03/16 14:36:51 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -35,6 +35,8 @@
3535
#defineUSE_DATE_CACHE 1
3636
#defineROUND_ALL 0
3737

38+
staticintDecodePosixTimezone(char*str,int*val);
39+
3840
intday_tab[2][13]= {
3941
{31,28,31,30,31,30,31,31,30,31,30,31,0},
4042
{31,29,31,30,31,30,31,31,30,31,30,31,0}};
@@ -47,15 +49,6 @@ char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
4749
"Thursday","Friday","Saturday",NULL};
4850

4951

50-
#if0
51-
52-
53-
staticvoidGetEpochTime(structtm*tm);
54-
55-
56-
#endif
57-
58-
5952
#defineUTIME_MINYEAR (1901)
6053
#defineUTIME_MINMONTH (12)
6154
#defineUTIME_MINDAY (14)
@@ -399,35 +392,6 @@ j2day(int date)
399392
}/* j2day() */
400393

401394

402-
#if0
403-
404-
405-
staticdouble
406-
time2t(constinthour,constintmin,constdoublesec)
407-
{
408-
return (((hour*60)+min)*60)+sec;
409-
}/* time2t() */
410-
411-
staticvoid
412-
dt2time(Timestampjd,int*hour,int*min,double*sec)
413-
{
414-
doubletime;
415-
416-
time=jd;
417-
418-
*hour= (time /3600);
419-
time-= ((*hour)*3600);
420-
*min= (time /60);
421-
time-= ((*min)*60);
422-
*sec=JROUND(time);
423-
424-
return;
425-
}/* dt2time() */
426-
427-
428-
#endif
429-
430-
431395
/*
432396
* parse and convert date in timestr (the normal interface)
433397
*
@@ -493,9 +457,12 @@ ParseDateTime(char *timestr, char *lowstr,
493457
while (isalpha(*cp))
494458
*lp++=tolower(*cp++);
495459

496-
/* full date string with leading text month? */
460+
/* Full date string with leading text month?
461+
* Could also be a POSIX time zone...
462+
*/
497463
if ((*cp=='-')|| (*cp=='/')|| (*cp=='.'))
498464
{
465+
#if0
499466
/*
500467
* special case of Posix timezone "GMT-0800"
501468
* Note that other sign (e.g. "GMT+0800"
@@ -512,6 +479,7 @@ ParseDateTime(char *timestr, char *lowstr,
512479
*cp='+';
513480
continue;
514481
}
482+
#endif
515483

516484
ftype[nf]=DTK_DATE;
517485
while (isdigit(*cp)|| (*cp=='-')|| (*cp=='/')|| (*cp=='.'))
@@ -627,7 +595,21 @@ DecodeDateTime(char **field, int *ftype, int nf,
627595
switch (ftype[i])
628596
{
629597
caseDTK_DATE:
630-
if (DecodeDate(field[i],fmask,&tmask,tm)!=0)
598+
/* Already have a date?
599+
* Then this might be a POSIX time zone
600+
* with an embedded dash (e.g. "PST-3" == "EST")
601+
* - thomas 2000-03-15
602+
*/
603+
if ((fmask&DTK_DATE_M)==DTK_DATE_M)
604+
{
605+
if ((tzp==NULL)
606+
|| (DecodePosixTimezone(field[i],tzp)!=0))
607+
return-1;
608+
609+
ftype[i]=DTK_TZ;
610+
tmask=DTK_M(TZ);
611+
}
612+
elseif (DecodeDate(field[i],fmask,&tmask,tm)!=0)
631613
return-1;
632614
break;
633615

@@ -646,9 +628,29 @@ DecodeDateTime(char **field, int *ftype, int nf,
646628
caseDTK_TZ:
647629
if (tzp==NULL)
648630
return-1;
649-
if (DecodeTimezone(field[i],tzp)!=0)
650-
return-1;
651-
tmask=DTK_M(TZ);
631+
632+
{
633+
inttz;
634+
635+
if (DecodeTimezone(field[i],&tz)!=0)
636+
return-1;
637+
638+
/* Already have a time zone?
639+
* Then maybe this is the second field of a POSIX time:
640+
* EST+3 (equivalent to PST)
641+
*/
642+
if ((i>0)&& ((fmask&DTK_M(TZ))!=0)
643+
&& (ftype[i-1]==DTK_TZ)&& (isalpha(*field[i-1])))
644+
{
645+
*tzp-=tz;
646+
tmask=0;
647+
}
648+
else
649+
{
650+
*tzp=tz;
651+
tmask=DTK_M(TZ);
652+
}
653+
}
652654
break;
653655

654656
caseDTK_NUMBER:
@@ -779,32 +781,15 @@ DecodeDateTime(char **field, int *ftype, int nf,
779781
if (tzp==NULL)
780782
return-1;
781783
*tzp=val*60;
784+
ftype[i]=DTK_TZ;
782785
break;
783786

784787
caseTZ:
785788
tm->tm_isdst=0;
786789
if (tzp==NULL)
787790
return-1;
788791
*tzp=val*60;
789-
790-
/* Swallow an immediately succeeding timezone if this is GMT
791-
* This handles the odd case in FreeBSD of "GMT+0800"
792-
* but note that we need to flip the sign on this too.
793-
* Claims to be some sort of POSIX standard format :(
794-
* - thomas 2000-01-20
795-
*/
796-
if ((i< (nf-1))&& (ftype[i+1]==DTK_TZ)
797-
&& (strcmp(field[i],"gmt")==0))
798-
{
799-
i++;
800-
if (DecodeTimezone(field[i],tzp)!=0)
801-
return-1;
802-
803-
/* flip the sign per POSIX standard */
804-
*tzp=-(*tzp);
805-
}
806-
807-
792+
ftype[i]=DTK_TZ;
808793
break;
809794

810795
caseIGNORE:
@@ -962,6 +947,19 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
962947
{
963948
switch (ftype[i])
964949
{
950+
caseDTK_DATE:
951+
/* This might be a POSIX time zone
952+
* with an embedded dash (e.g. "PST-3" == "EST")
953+
* - thomas 2000-03-15
954+
*/
955+
if ((tzp==NULL)
956+
|| (DecodePosixTimezone(field[i],tzp)!=0))
957+
return-1;
958+
959+
ftype[i]=DTK_TZ;
960+
tmask=DTK_M(TZ);
961+
break;
962+
965963
caseDTK_TIME:
966964
if (DecodeTime(field[i],fmask,&tmask,tm,fsec)!=0)
967965
return-1;
@@ -970,9 +968,29 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
970968
caseDTK_TZ:
971969
if (tzp==NULL)
972970
return-1;
973-
if (DecodeTimezone(field[i],tzp)!=0)
974-
return-1;
975-
tmask=DTK_M(TZ);
971+
972+
{
973+
inttz;
974+
975+
if (DecodeTimezone(field[i],&tz)!=0)
976+
return-1;
977+
978+
/* Already have a time zone?
979+
* Then maybe this is the second field of a POSIX time:
980+
* EST+3 (equivalent to PST)
981+
*/
982+
if ((i>0)&& ((fmask&DTK_M(TZ))!=0)
983+
&& (ftype[i-1]==DTK_TZ)&& (isalpha(*field[i-1])))
984+
{
985+
*tzp-=tz;
986+
tmask=0;
987+
}
988+
else
989+
{
990+
*tzp=tz;
991+
tmask=DTK_M(TZ);
992+
}
993+
}
976994
break;
977995

978996
caseDTK_NUMBER:
@@ -1015,6 +1033,41 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
10151033

10161034
break;
10171035

1036+
caseDTZMOD:
1037+
1038+
/*
1039+
* daylight savings time modifier (solves "MET
1040+
* DST" syntax)
1041+
*/
1042+
tmask |=DTK_M(DTZ);
1043+
tm->tm_isdst=1;
1044+
if (tzp==NULL)
1045+
return-1;
1046+
*tzp+=val*60;
1047+
break;
1048+
1049+
caseDTZ:
1050+
1051+
/*
1052+
* set mask for TZ here _or_ check for DTZ later
1053+
* when getting default timezone
1054+
*/
1055+
tmask |=DTK_M(TZ);
1056+
tm->tm_isdst=1;
1057+
if (tzp==NULL)
1058+
return-1;
1059+
*tzp=val*60;
1060+
ftype[i]=DTK_TZ;
1061+
break;
1062+
1063+
caseTZ:
1064+
tm->tm_isdst=0;
1065+
if (tzp==NULL)
1066+
return-1;
1067+
*tzp=val*60;
1068+
ftype[i]=DTK_TZ;
1069+
break;
1070+
10181071
caseIGNORE:
10191072
break;
10201073

@@ -1486,6 +1539,47 @@ DecodeTimezone(char *str, int *tzp)
14861539
}/* DecodeTimezone() */
14871540

14881541

1542+
/* DecodePosixTimezone()
1543+
* Interpret string as a POSIX-compatible timezone:
1544+
* PST-hh:mm
1545+
* PST+h
1546+
* - thomas 2000-03-15
1547+
*/
1548+
staticint
1549+
DecodePosixTimezone(char*str,int*tzp)
1550+
{
1551+
intval,tz;
1552+
inttype;
1553+
char*cp;
1554+
chardelim;
1555+
1556+
cp=str;
1557+
while ((*cp!='\0')&&isalpha(*cp))
1558+
cp++;
1559+
1560+
if (DecodeTimezone(cp,&tz)!=0)
1561+
return-1;
1562+
1563+
delim=*cp;
1564+
*cp='\0';
1565+
type=DecodeSpecial(MAXDATEFIELDS-1,str,&val);
1566+
*cp=delim;
1567+
1568+
switch(type)
1569+
{
1570+
caseDTZ:
1571+
caseTZ:
1572+
*tzp= (val*60)-tz;
1573+
break;
1574+
1575+
default:
1576+
return-1;
1577+
}
1578+
1579+
return0;
1580+
}/* DecodePosixTimezone() */
1581+
1582+
14891583
/* DecodeSpecial()
14901584
* Decode text string using lookup table.
14911585
* Implement a cache lookup since it is likely that dates

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp