1
1
/* -----------------------------------------------------------------------
2
2
* formatting.c
3
3
*
4
- * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.102 2005/11/22 18:17:22 momjian Exp $
4
+ * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.103 2005/12/03 16:45:06 momjian Exp $
5
5
*
6
6
*
7
7
* Portions Copyright (c) 1999-2005, PostgreSQL Global Development Group
@@ -434,6 +434,10 @@ do { \
434
434
tmtcTzn(_X) = NULL; \
435
435
} while(0)
436
436
437
+ /*
438
+ * to_char(time) appears to to_char() as an interval, so this check
439
+ * is really for interval and time data types.
440
+ */
437
441
#define INVALID_FOR_INTERVAL \
438
442
do { \
439
443
if (is_interval) \
@@ -1722,11 +1726,10 @@ dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
1722
1726
{
1723
1727
case DCH_A_M :
1724
1728
case DCH_P_M :
1725
- INVALID_FOR_INTERVAL ;
1726
1729
if (is_to_char )
1727
1730
{
1728
- strcpy (inout , (( tm -> tm_hour > 11
1729
- && tm -> tm_hour < HOURS_PER_DAY ) ? P_M_STR : A_M_STR ) );
1731
+ strcpy (inout , (tm -> tm_hour % HOURS_PER_DAY >= HOURS_PER_DAY / 2 )
1732
+ ? P_M_STR : A_M_STR );
1730
1733
return strlen (p_inout );
1731
1734
}
1732
1735
else
@@ -1742,11 +1745,10 @@ dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
1742
1745
break ;
1743
1746
case DCH_AM :
1744
1747
case DCH_PM :
1745
- INVALID_FOR_INTERVAL ;
1746
1748
if (is_to_char )
1747
1749
{
1748
- strcpy (inout , (( tm -> tm_hour > 11
1749
- && tm -> tm_hour < HOURS_PER_DAY ) ? PM_STR : AM_STR ) );
1750
+ strcpy (inout , (tm -> tm_hour % HOURS_PER_DAY >= HOURS_PER_DAY / 2 )
1751
+ ? PM_STR : AM_STR );
1750
1752
return strlen (p_inout );
1751
1753
}
1752
1754
else
@@ -1762,11 +1764,10 @@ dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
1762
1764
break ;
1763
1765
case DCH_a_m :
1764
1766
case DCH_p_m :
1765
- INVALID_FOR_INTERVAL ;
1766
1767
if (is_to_char )
1767
1768
{
1768
- strcpy (inout , (( tm -> tm_hour > 11
1769
- && tm -> tm_hour < HOURS_PER_DAY ) ? p_m_STR : a_m_STR ) );
1769
+ strcpy (inout , (tm -> tm_hour % HOURS_PER_DAY >= HOURS_PER_DAY / 2 )
1770
+ ? p_m_STR : a_m_STR );
1770
1771
return strlen (p_inout );
1771
1772
}
1772
1773
else
@@ -1782,11 +1783,10 @@ dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
1782
1783
break ;
1783
1784
case DCH_am :
1784
1785
case DCH_pm :
1785
- INVALID_FOR_INTERVAL ;
1786
1786
if (is_to_char )
1787
1787
{
1788
- strcpy (inout , (( tm -> tm_hour > 11
1789
- && tm -> tm_hour < HOURS_PER_DAY ) ? pm_STR : am_STR ) );
1788
+ strcpy (inout , (tm -> tm_hour % HOURS_PER_DAY >= HOURS_PER_DAY / 2 )
1789
+ ? pm_STR : am_STR );
1790
1790
return strlen (p_inout );
1791
1791
}
1792
1792
else
@@ -1804,12 +1804,9 @@ dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
1804
1804
case DCH_HH12 :
1805
1805
if (is_to_char )
1806
1806
{
1807
- if (is_interval )
1808
- sprintf (inout , "%0*d" , S_FM (suf ) ? 0 : 2 , tm -> tm_hour );
1809
- else
1810
- sprintf (inout , "%0*d" , S_FM (suf ) ? 0 : 2 ,
1811
- tm -> tm_hour == 0 ? 12 :
1812
- tm -> tm_hour < 13 ? tm -> tm_hour : tm -> tm_hour - 12 );
1807
+ sprintf (inout , "%0*d" , S_FM (suf ) ? 0 : 2 ,
1808
+ tm -> tm_hour % (HOURS_PER_DAY / 2 ) == 0 ? 12 :
1809
+ tm -> tm_hour % (HOURS_PER_DAY / 2 ));
1813
1810
if (S_THth (suf ))
1814
1811
str_numth (p_inout , inout , 0 );
1815
1812
return strlen (p_inout );
@@ -2312,7 +2309,6 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
2312
2309
}
2313
2310
break ;
2314
2311
case DCH_D :
2315
- INVALID_FOR_INTERVAL ;
2316
2312
if (is_to_char )
2317
2313
{
2318
2314
sprintf (inout , "%d" , tm -> tm_wday + 1 );
0 commit comments