You are looking at historical revision 13853 of this page. It may differ significantly from its current revision.
locale
Provides locale operations.
- locale
- Documentation
- Locale Components
- Generic Locale Components Property Access
- Timezone
- current-timezone
- current-timezone-component
- timezone-components?
- timezone-component-ref
- set-timezone-component!
- timezone-dst-rule-julian-noleap?
- timezone-dst-rule-julian-leap?
- timezone-dst-rule-mwd?
- timezone-dst-rule-offset
- timezone-dst-rule-julian
- timezone-dst-rule-month
- timezone-dst-rule-week
- timezone-dst-rule-day
- make-timezone-dst-rule-julian-leap
- make-timezone-dst-rule-julian-noleap
- make-timezone-dst-rule-mwd
- posix-timezone-string->timezone-components
- posix-load-timezon
- Locale
- Locale Category
- Usage
- Examples
- Notes
- Requirements
- Bugs and Limitations
- Author
- Version history
- 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 Components
The major data structure is the locale-components type, 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.
- name
- The composite information object, source specific.
- source
- The origin for the information.
The source property is one of the following (others are possible):
- POSIX
- Information from POSIX environment. The "name" is a string.
- PLATFORM
- Information from the system.
- BUILTIN
- Information from system defaults.
The PLATFORM source is used for information first. Then the POSIX source is attempted. When all have failed the BUILTIN source is used. 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.
Generic Locale Components Property Access
locale-components?
[procedure] (locale-components? OBJECT)Is the OBJECT a locale-compenents object?
locale-component-ref
[procedure] (locale-component-ref LOCALE-COMPONENTS KEY [DEFAULT #f])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.
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
[parameter] (current-timezone [VALUE])The currently defined timezone. The specified VALUE is either a timezone string value, or #f , indicating no timezone. When no timezone value is set the default timezone is UTC.
current-timezone-component
[procedure] (current-timezone-components)Returns the timezone-components object corresponding to the current-timezone.
timezone-components?
[procedure] (timezone-components? TIMEZONE-COMPONENTS)Is the specified TIMEZONE-COMPONENTS object actually a timezone-components object?
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.
timezone-dst-rule-julian-noleap?
[procedure] (timezone-dst-rule-julian-noleap? TIMEZONE-DST-RULE)Is the specified TIMEZONE-DST-RULE object actually a daylight saving time julian day without leap seconds object?
timezone-dst-rule-julian-leap?
[procedure] (timezone-dst-rule-julian-leap? TIMEZONE-DST-RULE)Is the specified TIMEZONE-DST-RULE object actually a daylight saving time julian day assuming leap seconds object?
timezone-dst-rule-mwd?
[procedure] (timezone-dst-rule-mwd? TIMEZONE-DST-RULE)Is the specified TIMEZONE-DST-RULE object actually a daylight saving time month+week+day object?
timezone-dst-rule-offset
[procedure] (timezone-dst-rule-offset TIMEZONE-DST-RULE)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)Returns the julian day component of the specified TIMEZONE-DST-RULE object.
timezone-dst-rule-month
[procedure] (timezone-dst-rule-month TIMEZONE-DST-RULE)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)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)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)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)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)Returns a daylight saving time month.week.day rule object.
posix-timezone-string->timezone-components
[procedure] (posix-timezone-string->timezone-components STRING [SOURCE "POSIX"])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-timezon
[procedure] (posix-load-timezone)Initialize the current-timezone from the TZ environment variable.
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
[parameter] (current-locale [VALUE])The currently defined locale. The specified VALUE is either a locale string value, or #f , indicating locale independence. When no locale value is set the default locale is #f.
current-locale-component
[procedure] (current-locale-components)Returns the locale-components object corresponding to the current-locale.
locale-components?
[procedure] (locale-components? LOCALE-COMPONENTS)Is the specified LOCALE-COMPONENTS object actually a locale-components object?
locale-component-ref
[procedure] (locale-component-ref LOCALE-COMPONENTS KEY [DEFAULT #f])Returns the locale-component KEY of the LOCALE-COMPONENTS object, or the DEFAULT for a missing component.
set-locale-component!
[procedure] (set-locale-component! LOCALE-COMPONENTS KEY VALUE)Sets the locale-component KEY of the LOCALE-COMPONENTS object to VALUE.
posix-locale-string->locale-components
[procedure] (posix-locale-string->locale-components STRING [SOURCE "POSIX"])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.
Locale Category
Access to the locale information by category.
Locale Category Keys:
- ADDRESS
- COLLATE
- CTYPE
- IDENTIFICATION
- LANGUAGE
- MEASUREMENT
- MESSAGES
- MONETARY
- NAME
- NUMERIC
- PAPER
- TELEPHONE
- TIME
set-locale-category!
[procedure] (set-locale-category! CATEGORY LOCALE-COMPONENTS)Sets the specified CATEGORY to the specified LOCALE-COMPONENTS object.
locale-category-ref
[procedure] (locale-category-ref CATEGORY)Returns the specified CATEGORY locale-components object, or #f if the category is not valued.
Usage
(require-extension locale)
Examples
Notes
- This is a work in progress. Currently only the Posix locale information is supported. Plans are to support the native MacOS X and Windows locale APIs. Changes to this API are almost certain.
Requirements
Bugs and Limitations
Author
Version history
- 0.4.0
- Added "default" timezone & locale
- 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.