How to define a custom locale with my own calendar settings?

1

I want to define a custom locale with my own calendar settings. In this locale, we set a specified year as the first year. For example, if I define a en_UNIX.UTF-8, I'd like to set AD 1970 as year 1, and AD 1970 as year 2.

Is there any way to do this in Linux/BSD? I looked into system's locale files and found they only defined the first day of week, currency and so on except the first year of calendar...

Lingfeng Xiong

Posted 2013-04-24T13:59:06.413

Reputation: 287

Answers

0

Use of the gregorian calendar is hard-coded in glibc: https://github.com/rbdixon/glibc/blob/master/time/offtime.c#L58

So anything that uses the C library ("system") routines - gmtime_r, localtime_r and so on - to convert between seconds-since-the-epoch and broken-down-date format, will stick to the "standard" calendar (365 days in a year, Gregorian leap-year formula, 7 days per week...).

For code you write yourself, you could use the ICU Project's libraries and provide your own non-Gergorian calendar specification in the Unicode Common Locale Data Repository XML format.

I'm pretty sure you don't want to do that.

Gabe

Posted 2013-04-24T13:59:06.413

Reputation: 1 837

I found many GNOME applications are depends on libicu, is there anyway to set non-Gergorian calender for these applications? – Lingfeng Xiong – 2013-04-25T12:29:02.980

@LingfengXiong Not usefully, because libicu is probably mostly used to deal with unicode character set and font handling for internationalisation, not for date handling. It may be used for that, but there's not much of a way to find out: you'd need to find/create a suitable calendar definition, make sure it's installed/available, set your timezone to that one, and see if it makes a difference. And even if it does, it might not in all places in the code, and if it doesn't, perhaps that build simply can't or won't load it without a recompile, but would. – Gabe – 2013-04-25T16:27:47.953

thanks for your kindly help :-) Does Mac OS X (GUI applications) and FreeBSD handle this kind of things in the same way? – Lingfeng Xiong – 2013-04-26T09:43:21.867

The situation on FreeBSD is essentially identical to Linux; I have absolutely no idea what support MacOS provides for time/date handling beyond basic Unix routines, and to what extent you can expect it to be used. – Gabe – 2013-04-26T12:19:41.057