Обсуждение: Ordinal suffix behaviour
G'day folks,
The enclosed patch changes the behaviour of the "ordinal" ('TH') format for
to_char. I don't know about the rest of the world, but the "standard" in
Australia is the following:
1st, 2nd, 3rd, 4th - 9th
10th - 19th
21st, 22nd, 23rd, 24th - 29th (similarly for 30s - 90s)
110th - 119th (and for all "teens")
121st, 122nd, 123rd, 124th - 129th
I think you see the trend. The current code works fine except that it
produces:
111st, 112nd, 113rd, 114th - 119th
211st, 212nd, 213rd, 214th - 219th ... and so on.
Without knowing anything about what's supported (and what isn't) in the usual
I18N libraries, should this type of behaviour be defined within the locales?
*** src/backend/utils/adt/formatting.c.orig Fri Jun 9 04:33:30 2000
--- src/backend/utils/adt/formatting.c Fri Jun 9 04:35:48 2000
***************
*** 1258,1271 ****
get_th(char *num, int type)
{
int len = strlen(num),
! last;
last = *(num + (len - 1));
if (!isdigit((unsigned char) last))
elog(ERROR, "get_th: '%s' is not number.", num);
! /* 11 || 12 */
! if (len == 2 && (last == '1' || last == '2') && *num == '1')
last = 0;
switch (last)
--- 1258,1274 ----
get_th(char *num, int type)
{
int len = strlen(num),
! last, seclast;
last = *(num + (len - 1));
if (!isdigit((unsigned char) last))
elog(ERROR, "get_th: '%s' is not number.", num);
! /*
! * All "teens" (<x>1[0-9]) get 'TH/th',
! * while <x>[02-9][123] still get 'ST/st', 'ND/nd', 'RD/rd', respectively
! */
! if ((len > 1) && ((seclast = num[len-2]) == '1'))
last = 0;
switch (last)
-------------------------------------------------------+---------------------
Daniel Baldoni BAppSc, PGradDipCompSci | Technical Director
require 'std/disclaimer.pl' | LcdS Pty. Ltd.
-------------------------------------------------------+ 856B Canning Hwy
Phone/FAX: +61-8-9364-8171 | Applecross
Mobile: 041-888-9794 | WA 6153
URL: http://www.lcds.com.au/ | Australia
-------------------------------------------------------+---------------------
"Any time there's something so ridiculous that no rational systems programmer
would even consider trying it, they send for me."; paraphrased from "King Of
The Murgos" by David Eddings. (I'm not good, just crazy)
On 08 Jun 2000 21:01:37 GMT Daniel Baldoni wrote: > Without knowing anything about what's supported (and what isn't) in the usual > I18N libraries, should this type of behaviour be defined within the > locales? It's not defined in POSIX or the "Single Unix Specification, version 2". Or at least if it is defined, I can neither see it nor remember it. ;-) Regards, Giles
Applied. Thanks.
> G'day folks,
>
> The enclosed patch changes the behaviour of the "ordinal" ('TH') format for
> to_char. I don't know about the rest of the world, but the "standard" in
> Australia is the following:
>
> 1st, 2nd, 3rd, 4th - 9th
> 10th - 19th
> 21st, 22nd, 23rd, 24th - 29th (similarly for 30s - 90s)
> 110th - 119th (and for all "teens")
> 121st, 122nd, 123rd, 124th - 129th
>
> I think you see the trend. The current code works fine except that it
> produces:
>
> 111st, 112nd, 113rd, 114th - 119th
> 211st, 212nd, 213rd, 214th - 219th ... and so on.
>
> Without knowing anything about what's supported (and what isn't) in the usual
> I18N libraries, should this type of behaviour be defined within the locales?
>
> *** src/backend/utils/adt/formatting.c.orig Fri Jun 9 04:33:30 2000
> --- src/backend/utils/adt/formatting.c Fri Jun 9 04:35:48 2000
> ***************
> *** 1258,1271 ****
> get_th(char *num, int type)
> {
> int len = strlen(num),
> ! last;
>
> last = *(num + (len - 1));
> if (!isdigit((unsigned char) last))
> elog(ERROR, "get_th: '%s' is not number.", num);
>
> ! /* 11 || 12 */
> ! if (len == 2 && (last == '1' || last == '2') && *num == '1')
> last = 0;
>
> switch (last)
> --- 1258,1274 ----
> get_th(char *num, int type)
> {
> int len = strlen(num),
> ! last, seclast;
>
> last = *(num + (len - 1));
> if (!isdigit((unsigned char) last))
> elog(ERROR, "get_th: '%s' is not number.", num);
>
> ! /*
> ! * All "teens" (<x>1[0-9]) get 'TH/th',
> ! * while <x>[02-9][123] still get 'ST/st', 'ND/nd', 'RD/rd', respectively
> ! */
> ! if ((len > 1) && ((seclast = num[len-2]) == '1'))
> last = 0;
>
> switch (last)
>
>
>
> -------------------------------------------------------+---------------------
> Daniel Baldoni BAppSc, PGradDipCompSci | Technical Director
> require 'std/disclaimer.pl' | LcdS Pty. Ltd.
> -------------------------------------------------------+ 856B Canning Hwy
> Phone/FAX: +61-8-9364-8171 | Applecross
> Mobile: 041-888-9794 | WA 6153
> URL: http://www.lcds.com.au/ | Australia
> -------------------------------------------------------+---------------------
> "Any time there's something so ridiculous that no rational systems programmer
> would even consider trying it, they send for me."; paraphrased from "King Of
> The Murgos" by David Eddings. (I'm not good, just crazy)
>
--
Bruce Momjian | http://www.op.net/~candle
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026