Outdated egg!

This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for the CHICKEN 4 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

locale

Provides locale operations.

  1. Outdated egg!
  2. locale
  3. Documentation
    1. Locale Components
    2. Locale Components
      1. make-locale-components
      2. locale-components?
      3. locale-components-exists?
      4. locale-component-ref
      5. set-locale-component!
      6. update-locale-components!
    3. Locale
      1. current-locale
      2. current-locale-component
      3. posix-locale-string->locale-components
      4. posix-load-local
    4. Timezone
      1. current-timezone
      2. current-timezone-component
      3. posix-timezone-string->timezone-components
      4. posix-load-timezone
    5. Timezone Components
      1. make-timezone-components
      2. timezone-components?
      3. timezone-components-exists?
      4. timezone-component-ref
      5. set-timezone-component!
      6. update-timezone-components!
      7. timezone-dst-rule-julian-noleap?
      8. timezone-dst-rule-julian-leap?
      9. timezone-dst-rule-mwd?
      10. timezone-dst-rule-offset
      11. timezone-dst-rule-julian
      12. timezone-dst-rule-month
      13. timezone-dst-rule-week
      14. timezone-dst-rule-day
      15. make-timezone-dst-rule-julian-leap
      16. make-timezone-dst-rule-julian-noleap
      17. make-timezone-dst-rule-mwd
      18. local-timezone
      19. local-timezone-offset
      20. with-tzset
    6. Locale Category
      1. make-locale-dictionary
      2. locale-dictionary?
      3. locale-dictionary-category
      4. set-locale-dictionary-category!
      5. current-locale-dictionary
      6. locale-category-ref
      7. set-locale-category!
  4. Usage
  5. Examples
  6. Notes
  7. Requirements
  8. Bugs and Limitations
  9. Author
  10. Version history
  11. License

Documentation

locale is a set of routines supporting locale query operations. The environment locale information is determined upon module load and the corresponding parameters are set.

locale does not interact with the C library routines setlocale or tzset, except for the with-tzset routine (see below).

locale does not provide a localized message service, see SRFI 29.

locale does not provide a localized time service, see SRFI 19.

locale does not provide a localized collating service.

locale does not provide much of anything beyond locale identification.

Locale Components

The major data structure is the locale-components object, portrayed as an extensible key+value pairing. The key is a symbol. The value is usually a string.

A locale-components object will have more properties but the following are provided for every instance:

Common Component Keys:

tag
What kind. Examples: 'locale and 'timezone.
name
The composite information object, source specific.
source
The origin for the information.

A primary source is one of the following (others are possible):

PLATFORM
Information from the system.
POSIX
Information from POSIX environment. The "name" is a string.
GNU
Information from GNU environment.
BUILTIN
Information from system defaults.

The point being locale information will be available, but without an accuracy guarantee.

The BUILTIN source creates a POSIX-style string "name" constructed using constants and library procedures.

The source is either a string or a (string object...):

POSIX
("POSIX" "<environment variable name>"). Example: ("POSIX" "TZ").
GNU
("GNU" "<environment variable name>"). Example: ("GNU" "LANGUAGE").

Locale Components

make-locale-components

[procedure] (make-locale-components NAME [SOURCE #f [TAG 'locale]]) => LOCALE-COMPONENTS

Returns a new locale-components object.

locale-components?

[procedure] (locale-components? OBJECT) => BOOLEAN

Is the OBJECT a locale-compenents object?

locale-components-exists?

[procedure] (locale-components-exists? LOCALE-COMPONENTS KEY) => BOOLEAN

Does the specified LOCALE-COMPONENTS have a value for KEY?

locale-component-ref

[procedure] (locale-component-ref LOCALE-COMPONENTS KEY [DEFAULT #f]) => OBJECT

Returns the KEY property of LOCALE-COMPONENTS or the DEFAULT when not found.

set-locale-component!

[procedure] (set-locale-component! LOCALE-COMPONENTS KEY VALUE)

Updates or creates the KEY property of LOCALE-COMPONENTS with the VALUE.

update-locale-components!

[procedure] (update-locale-components! LOCALE-COMPONENTS KEY VALUE ...) => LOCALE-COMPONENTS

Updates in place the LOCALE-COMPONENTS with the specified KEY+VALUE pairs.

Locale

Access to locale information. A locale object is composed of a Language, an optional Script, an optional Region, an optional Codeset, and an optional Modifier. The language should be an ISO 639-1 or ISO 639-2 name. The Script should be a RFC 3066bis name. The region should be an ISO 3166-1 name. The codeset and modifier forms are locale dependent.

Locale Properties:

language
ISO 639-1 or ISO 639-2 name string. Default "en".
script
RFC 3066bis name string.
region
ISO 3166-1 name string. Default "US".
codeset
The character code to character mapping system.
modifier
Instance data, if any.

current-locale

[procedure] (current-locale) => STRING
[procedure] (current-locale VALUE)

The currently defined locale. Returns the locale name string.

The specified VALUE is either a locale string value, a locale-components object or #f, indicating locale independence.

When no locale value is set the default locale is #f.

current-locale-component

[procedure] (current-locale-components) => LOCALE-COMPONENTS

Returns the locale-components object corresponding to the current-locale.

posix-locale-string->locale-components

[procedure] (posix-locale-string->locale-components STRING [SOURCE "POSIX" [TAG 'locale]]) => LOCALE-COMPONENTS

Parses a POSIX locale string specification, STRING, and returns the corresponding locale-components object, or #f when a parse error occurs. A #f or empty string value is mapped to the default locale. The optional SOURCE indicates what locale system supplied the string.

posix-load-local

[procedure] (posix-load-locale)

Sets up the locale using POSIX rules. Initializes the current-locale from the MESSAGES category.

The Posix pathname locale is currently unsupported.

The "C" & "POSIX" locales are unsupported.

Timezone

Access to timezone information. A timezone object is a locale-components object with properties for Standard Time Name and Offset, and an optional Summer or Daylight Saving Time Name and Offset. The offset is seconds west (positive or east (negative of UTC. The name is some locally accepted timezone name, such as "PST". A Daylight Saving Time start rule and end rule are optional properties.

Timezone Component Properties:

std-name
The Standard timezone name.
std-offset
Seconds +/- UTC.
dst-name
The Daylight Saving Time timezone name.
dst-offset
Seconds +/- UTC.
dst-start
The start of Daylight Saving Time; a timezone-dst-rule.
dst-end
The end of Daylight Saving Time; a timezone-dst-rule.

current-timezone

[procedure] (current-timezone) => STRING
[procedure] (current-timezone VALUE)

The currently defined timezone. Retruns the timezone name string.

The specified VALUE is either a timezone string value, a timezone-components or #f, indicating no timezone.

When no timezone value is set the default timezone is UTC.

current-timezone-component

[procedure] (current-timezone-components) => TIMEZONE-COMPONENTS

Returns the timezone-components object corresponding to the current-timezone.

posix-timezone-string->timezone-components

[procedure] (posix-timezone-string->timezone-components STRING [SOURCE "POSIX"]) => TIMEZONE-COMPONENTS

Parses a POSIX timezone string specification, STRING, and returns the corresponding timezone-components object, or #f when a parse error occurs. A #f or empty string value is mapped to the default timezone. The optional SOURCE indicates what locale system supplied the string.

posix-load-timezone

[procedure] (posix-load-timezone)

Initialize the current-timezone from the TZ environment variable.

The Posix pathname and implementation-defined timezone is currently unsupported.

Timezone Components

make-timezone-components

[procedure] (make-timezone-components NAME [SOURCE #f]) => TIMEZONE-COMPONENTS

Returns a new timezone-components object.

timezone-components?

[procedure] (timezone-components? OBJECT) => BOOLEAN

Is the specified OBJECT actually a timezone-components object?

Note that a timezone-components object is-a locale-compenents object.

timezone-components-exists?

[procedure] (timezone-components-exists? TIMEZONE-COMPONENTS KEY) => BOOLEAN

Does the specified TIMEZONE-COMPONENTS have a value for KEY?

timezone-component-ref

[procedure] (timezone-component-ref TIMEZONE-COMPONENTS KEY [DEFAULT #f])

Returns the timezone-component KEY of the TIMEZONE-COMPONENTS object, or the DEFAULT for a missing component.

set-timezone-component!

[procedure] (set-timezone-component! TIMEZONE-COMPONENTS KEY VALUE)

Sets the timezone-component KEY of the TIMEZONE-COMPONENTS object to VALUE.

update-timezone-components!

[procedure] (update-timezone-components! TIMEZONE-COMPONENTS KEY VALUE ...) => TIMEZONE-COMPONENTS

Updates in place the TIMEZONE-COMPONENTS with the specified KEY+VALUE pairs.

timezone-dst-rule-julian-noleap?

[procedure] (timezone-dst-rule-julian-noleap? OBJECT) => BOOLEAN

Is the specified OBJECT actually a daylight saving time julian day without leap seconds object?

timezone-dst-rule-julian-leap?

[procedure] (timezone-dst-rule-julian-leap? OBJECT) => BOOLEAN

Is the specified OBJECT actually a daylight saving time julian day assuming leap seconds object?

timezone-dst-rule-mwd?

[procedure] (timezone-dst-rule-mwd? OBJECT) => BOOLEAN

Is the specified OBJECT actually a daylight saving time month+week+day object?

timezone-dst-rule-offset

[procedure] (timezone-dst-rule-offset TIMEZONE-DST-RULE) => INTEGER

Returns the seconds within day offset component of the specified TIMEZONE-DST-RULE object.

timezone-dst-rule-julian

[procedure] (timezone-dst-rule-julian TIMEZONE-DST-RULE) => INTEGER

Returns the julian day component of the specified TIMEZONE-DST-RULE object.

timezone-dst-rule-month

[procedure] (timezone-dst-rule-month TIMEZONE-DST-RULE) => INTEGER

Returns the month of year component of the specified TIMEZONE-DST-RULE object.

timezone-dst-rule-week

[procedure] (timezone-dst-rule-week TIMEZONE-DST-RULE) => INTEGER

Returns the week of month component of the specified TIMEZONE-DST-RULE object.

timezone-dst-rule-day

[procedure] (timezone-dst-rule-day TIMEZONE-DST-RULE) => INTEGER

Returns the day of week component of the specified TIMEZONE-DST-RULE object.

make-timezone-dst-rule-julian-leap

[procedure] (make-timezone-dst-rule-julian-leap JULIAN-DAY OFFSET) => TIMEZONE-DST-RULE

Returns a daylight saving time julian day assuming leap seconds rule object.

make-timezone-dst-rule-julian-noleap

[procedure] (make-timezone-dst-rule-julian-noleap JULIAN-DAY OFFSET) => TIMEZONE-DST-RULE

Returns a daylight saving time julian day without leap seconds rule object.

make-timezone-dst-rule-mwd

[procedure] (make-timezone-dst-rule-mwd MONTH WEEK DAY OFFSET) => TIMEZONE-DST-RULE

Returns a daylight saving time month.week.day rule object.

local-timezone

[procedure] (local-timezone TM | YEAR MONTH DAY [HOUR 12 [MINUTE 0 [SECOND 0]]] [#:offset? OFFSET? #f]) => STRING

Returns the timezone for the given date as a string, (e.g. "EST"). If OFFSET? is #t, then return it in RFC-822 format (e.g. "-0500").

The date maybe specified using a 10-element time-vector TM or separately as YEAR MONTH DAY [HOUR 12 [MINUTE 0 [SECOND 0]]].

YEAR will be biased by -1900, except for a TM argument. ((MONTH}} in [0 11]. DAY in [1 31]. HOUR in [0 23]. MINUTE in [0 59]. SECOND in [0 60].

local-timezone-offset

[procedure] (local-timezone-offset TM | YEAR MONTH DAY [HOUR 12 [MINUTE 0 [SECOND 0]]]) => FIXNUM

Returns the timezone offset as seconds where positive is east of UTC & negative is west of UTC.

with-tzset

[procedure] (with-tzset TZ THUNK) => OBJECT

Invoke THUNK with the TZ environment variable bound to the string TZ. Uses the C library routine tzset. Restores the original TZ value.

Locale Category

Access to the locale information by category.

Locale Category Keys (others are possible):

address
A {{locale-components} object.
collate
A {{locale-components} object.
ctype
A {{locale-components} object.
identification
A {{locale-components} object.
language
A {{language-components} object.
measurement
A {{locale-components} object.
messages
A {{locale-components} object.
monetary
A {{locale-components} object.
name
A {{locale-components} object.
numeric
A {{locale-components} object.
paper
A {{locale-components} object.
telephone
A {{locale-components} object.
time
A {{locale-components} object.
timezone
A {{timezone-components} object.

make-locale-dictionary

[procedure] (make-locale-dictionary) => LOCALE-CATEGORIES

Returns a new locale-categories object.

locale-dictionary?

[procedure] (locale-dictionary? OBJECT) => BOOLEAN

Is the specified OBJECT a locale-categories object?

locale-dictionary-category

[procedure] (locale-dictionary-category LOCALE-CATEGORIES KEY [DEFAULT #f]) => OBJECT

Returns the value for KEY in the LOCALE-CATEGORIES.

set-locale-dictionary-category!

[procedure] (set-locale-dictionary-category! LOCALE-CATEGORIES KEY VALUE)

Changes the VALUE for KEY in the LOCALE-CATEGORIES. A VALUE of #f will delete the category identified by KEY.

current-locale-dictionary

[parameter] (current-locale-dictionary) => LOCALE-CATEGORIES
[parameter] (current-locale-dictionary LOCALE-CATEGORIES)

Gets and sets the current locale-categories object.

locale-category-ref

[procedure] (locale-category-ref CATEGORY [DEFAULT #f])

Returns the specified CATEGORY locale-components object, or #f if the category is not valued.

set-locale-category!

[procedure] (set-locale-category! CATEGORY LOCALE-COMPONENTS)

Sets the specified CATEGORY to the specified LOCALE-COMPONENTS object.

Usage

(require-extension locale)

Examples

Notes

Requirements

lookup-table miscmacros

Bugs and Limitations

Author

kon lovett

Version history

0.5.1
Added 'with-tzset'. Added TM argument support to 'local-timezone' & 'local-timezone-offset'.
0.5.0
Added 'local-timezone' & 'local-timezone-offset'.
0.4.0
Added "buitlin" timezone & locale. Added categories.
0.3.3
Removed use of 'critical-section'.
0.3.2
Dropped ':optional'.
0.3.1
Bug fix for default dst offset.
0.3
Reverts to defaults for timezone & locale when parse errors.
0.2
Exports.
0.1
Initial release.

License

Copyright (C 2009 Kon Lovett. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software, to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.