• Publicity: Public Only All

localization-procs.tcl

Routines for localizing numbers, dates and monetary amounts

This is free software distributed under the terms of the GNU Public License. Full text of the license is available from the GNU Project: http://www.fsf.org/copyleft/gpl.html

Location:
packages/acs-lang/tcl/localization-procs.tcl
Created:
30 September 2000
Authors:
Jeff Davis <davis@xarg.net>
Ashok Argent-Katwala <akatwala@arsdigita.com>
CVS Identification:
$Id: localization-procs.tcl,v 1.29.2.4 2019/07/01 16:43:43 hectorr Exp $

Procedures in this file

Detailed information

clock_to_ansi (public)

 clock_to_ansi seconds

Convert a time in the Tcl internal clock seconds format to ANSI format, usable by lc_time_fmt.

Parameters:
seconds
Returns:
ANSI (YYYY-MM-DD HH24:MI:SS) formatted date.
Author:
Lars Pind <lars@pinds.com>

See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 dt_next_month_name dt_next_month_name (public) clock_to_ansi clock_to_ansi dt_next_month_name->clock_to_ansi dt_prev_month_name dt_prev_month_name (public) dt_prev_month_name->clock_to_ansi packages/acs-admin/www/auth/login-attempts.tcl packages/acs-admin/ www/auth/login-attempts.tcl packages/acs-admin/www/auth/login-attempts.tcl->clock_to_ansi packages/categories/lib/contributions.tcl packages/categories/ lib/contributions.tcl packages/categories/lib/contributions.tcl->clock_to_ansi packages/xotcl-request-monitor/www/whos-online-today.tcl packages/xotcl-request-monitor/ www/whos-online-today.tcl packages/xotcl-request-monitor/www/whos-online-today.tcl->clock_to_ansi

Testcases:
No testcase defined.

lc_content_size_pretty (public)

 lc_content_size_pretty [ -size size ] [ -precision precision ] \
    [ -standard standard ]

Transforms data size, provided in non-negative bytes, to KB, MB... up to YB.

Switches:
-size (defaults to "0") (optional)
Size in bytes
-precision (defaults to "1") (optional)
Numbers in the fractional part
-standard (defaults to "decimal") (optional)
Standard to use for binary prefix. Three standards are supported currently by this proc: - decimal (default): SI (base-10, 1000 bytes = 1kB) - binary: IEC (base-2, 1024 bytes = 1KiB) - legacy: JEDEC (base-2, 1024 bytes = 1KB)
Returns:
Size in given standard units (e.g. '5.2 MB')
Author:
Héctor Romojaro
Created:
2019-06-25

Partial Call Graph (max 5 caller/called nodes):
%3 test_lang_test__lc_content_size_pretty lang_test__lc_content_size_pretty (test acs-lang) lc_content_size_pretty lc_content_size_pretty test_lang_test__lc_content_size_pretty->lc_content_size_pretty lc_get lc_get (public) lc_content_size_pretty->lc_get lc_numeric lc_numeric (public) lc_content_size_pretty->lc_numeric packages/acs-subsite/www/user/portrait/upload.tcl packages/acs-subsite/ www/user/portrait/upload.tcl packages/acs-subsite/www/user/portrait/upload.tcl->lc_content_size_pretty packages/attachments/www/attach.tcl packages/attachments/ www/attach.tcl packages/attachments/www/attach.tcl->lc_content_size_pretty packages/file-storage/lib/folder-links.tcl packages/file-storage/ lib/folder-links.tcl packages/file-storage/lib/folder-links.tcl->lc_content_size_pretty packages/file-storage/www/file.tcl packages/file-storage/ www/file.tcl packages/file-storage/www/file.tcl->lc_content_size_pretty packages/file-storage/www/folder-chunk.tcl packages/file-storage/ www/folder-chunk.tcl packages/file-storage/www/folder-chunk.tcl->lc_content_size_pretty

Testcases:
lang_test__lc_content_size_pretty

lc_get (public)

 lc_get [ -locale locale ] key

Get a certain format string for the current locale.

Switches:
-locale (optional)
Parameters:
key - the key of for the format string you want.
Returns:
the format string for the current locale.
Author:
Lars Pind <lars@pinds.com>

Partial Call Graph (max 5 caller/called nodes):
%3 calendar::get_month_multirow_information calendar::get_month_multirow_information (public) lc_get lc_get calendar::get_month_multirow_information->lc_get dt_month_abbrev dt_month_abbrev (public) dt_month_abbrev->lc_get dt_month_names dt_month_names (public) dt_month_names->lc_get lang::message::check lang::message::check (public) lang::message::check->lc_get lc_content_size_pretty lc_content_size_pretty (public) lc_content_size_pretty->lc_get

Testcases:
No testcase defined.

lc_list_all_timezones (public)

 lc_list_all_timezones
Returns:
list of pairs containing all timezone names and offsets. Data drawn from acs-reference package timezones table

Partial Call Graph (max 5 caller/called nodes):
%3 test_set_get_timezone set_get_timezone (test acs-lang) lc_list_all_timezones lc_list_all_timezones test_set_get_timezone->lc_list_all_timezones db_list_of_lists db_list_of_lists (public) lc_list_all_timezones->db_list_of_lists packages/acs-lang/www/admin/set-system-timezone.tcl packages/acs-lang/ www/admin/set-system-timezone.tcl packages/acs-lang/www/admin/set-system-timezone.tcl->lc_list_all_timezones packages/acs-lang/www/admin/test/tz-test.tcl packages/acs-lang/ www/admin/test/tz-test.tcl packages/acs-lang/www/admin/test/tz-test.tcl->lc_list_all_timezones

Testcases:
set_get_timezone

lc_numeric (public)

 lc_numeric num [ fmt ] [ locale ]

Given a number and a locale return a formatted version of the number for that locale.

Parameters:
num - Number in canonical form
fmt (optional) - Format string used by the Tcl format command (should be restricted to the form "%.Nf" if present).
locale (optional) - Locale
Returns:
Localized form of the number

Partial Call Graph (max 5 caller/called nodes):
%3 test_lang_test__lc_numeric lang_test__lc_numeric (test acs-lang) lc_numeric lc_numeric test_lang_test__lc_numeric->lc_numeric lc_get lc_get (public) lc_numeric->lc_get lc_sepfmt lc_sepfmt (private) lc_numeric->lc_sepfmt fs::get_folder_contents fs::get_folder_contents (public) fs::get_folder_contents->lc_numeric lc_content_size_pretty lc_content_size_pretty (public) lc_content_size_pretty->lc_numeric packages/acs-admin/www/auth/authority.tcl packages/acs-admin/ www/auth/authority.tcl packages/acs-admin/www/auth/authority.tcl->lc_numeric packages/acs-developer-support/lib/toolbar.tcl packages/acs-developer-support/ lib/toolbar.tcl packages/acs-developer-support/lib/toolbar.tcl->lc_numeric packages/acs-developer-support/www/request-info.tcl packages/acs-developer-support/ www/request-info.tcl packages/acs-developer-support/www/request-info.tcl->lc_numeric

Testcases:
lang_test__lc_numeric

lc_parse_number (public)

 lc_parse_number num locale [ integer_only_p ]

Converts a number to its canonical representation by stripping everything but the decimal separator and triming left 0's so it won't be octal. It can process the following types of numbers:

  • Just digits (allows leading zeros).
  • Digits with a valid thousands separator, used consistently (leading zeros not allowed)
  • Either of the above with a decimal separator plus optional digits after the decimal marker
The valid separators are taken from the given locale. Does not handle localized signed numbers in this version. The sign may only be placed before the number (with/without whitespace). Also allows the empty string, returning same.

Parameters:
num - Localized number
locale - Locale
integer_only_p (defaults to "0") - True if only integers returned
Returns:
Canonical form of the number
Error:
If unsupported locale or not a number

Partial Call Graph (max 5 caller/called nodes):
%3 test_lang_test__lc_numeric lang_test__lc_numeric (test acs-lang) lc_parse_number lc_parse_number test_lang_test__lc_numeric->lc_parse_number lc_get lc_get (public) lc_parse_number->lc_get packages/acs-lang/www/admin/test/format-test.tcl packages/acs-lang/ www/admin/test/format-test.tcl packages/acs-lang/www/admin/test/format-test.tcl->lc_parse_number packages/acs-lang/www/admin/test/test.tcl packages/acs-lang/ www/admin/test/test.tcl packages/acs-lang/www/admin/test/test.tcl->lc_parse_number

Testcases:
lang_test__lc_numeric

lc_time_conn_to_system (public)

 lc_time_conn_to_system time_value

Converts a date from the connection's timezone to the system (database) timezone, using the OpenACS timezone setting and user's preference

Parameters:
time_value - Timestamp from conn input in the ISO datetime format.
Returns:
Timestamp in the database's time zone, also in ISO datetime format.

Partial Call Graph (max 5 caller/called nodes):
%3 calendar::item::edit calendar::item::edit (public) lc_time_conn_to_system lc_time_conn_to_system calendar::item::edit->lc_time_conn_to_system calendar::item::new calendar::item::new (public) calendar::item::new->lc_time_conn_to_system packages/calendar/www/view-week-display.tcl packages/calendar/ www/view-week-display.tcl packages/calendar/www/view-week-display.tcl->lc_time_conn_to_system ad_conn ad_conn (public) lc_time_conn_to_system->ad_conn lc_time_tz_convert lc_time_tz_convert (public) lc_time_conn_to_system->lc_time_tz_convert

Testcases:
No testcase defined.

lc_time_fmt (public)

 lc_time_fmt datetime fmt [ locale ]

Formats a time for the specified locale.

Parameters:
datetime - Strictly in the form "YYYY-MM-DD HH24:MI:SS". Formulae for calculating day of week from the Calendar FAQ (http://www.tondering.dk/claus/calendar.html)
fmt - An ISO 14652 LC_TIME style formatting string. The highlighted functions localize automatically based on the user's locale; other strings will use locale-specific text but not necessarily locale-specific formatting.
      %a           FDCC-set's abbreviated weekday name.
      %A           FDCC-set's full weekday name.
      %b           FDCC-set's abbreviated month name.
      %B           FDCC-set's full month name.
      %c           FDCC-set's appropriate date and time
                   representation.
      %C           Century (a year divided by 100 and truncated to
                   integer) as decimal number (00-99).
      %d           Day of the month as a decimal number (01-31).
      %D           Date in the format mm/dd/yy.
      %e           Day of the month as a decimal number (1-31 in at
                   two-digit field with leading  fill).
      %E           Month number as a decimal number (1-12 in at
                   two-digit field with leading  fill).
      %f           Weekday as a decimal number (1(Monday)-7).
      %F           is replaced by the date in the format YYYY-MM-DD
                   (ISO 8601 format)
      %h           A synonym for %b.
      %H           Hour (24-hour clock) as a decimal number (00-23).
      %I           Hour (12-hour clock) as a decimal number (01-12).
      %j           Day of the year as a decimal number (001-366).
      %m           Month as a decimal number (01-13).
      %M           Minute as a decimal number (00-59).
      %n           A  character.
      %p           FDCC-set's equivalent of either AM or PM.
      %r           Hours and minutes using 12-hour clock AM/PM
                   notation, e.g. '06:12 AM'.
      %q           Long date without weekday (OpenACS addition to the standard)
      %Q           Long date with weekday (OpenACS addition to the standard)
      %S           Seconds as a decimal number (00-61).
      %t           A  character.
      %T           24-hour clock time in the format HH:MM:SS.
      %u           Week number of the year as a decimal number with
                   two digits and leading zero, according to "week"
                   keyword.
      %U           Week number of the year (Sunday as the first day of
                   the week) as a decimal number (00-53).
      %w           Weekday as a decimal number (0(Sunday)-6).
      %W           Week number of the year (Monday as the first day of
                   the week) as a decimal number (00-53).
      %x           FDCC-set's appropriate date representation.
      %X           FDCC-set's appropriate time representation.
      %y           Year (offset from %C) as a decimal number (00-99).
      %Y           Year with century as a decimal number.
      %Z           The connection's timezone, e.g. 'America/New_York'.
      %%           A  character.
    
See also
man strftime
on a UNIX shell prompt for more of these abbreviations.
locale (optional) - Locale identifier must be in the locale database
Returns:
A date formatted for a locale
Error:
Fails if given a non-existent locale or a malformed datetime Doesn't check for impossible dates. Ask it for 29 Feb 1999 and it will tell you it was a Monday (1st March was a Monday, it wasn't a leap year). Also it only works with the Gregorian calendar - but that's reasonable, but could be a problem if you are running a seriously historical site (or have an 'on this day in history' style page that goes back a good few hundred years).

Partial Call Graph (max 5 caller/called nodes):
%3 test_lang_test__lc_numeric lang_test__lc_numeric (test acs-lang) lc_time_fmt lc_time_fmt test_lang_test__lc_numeric->lc_time_fmt test_lc_time_fmt_Z_timezone lc_time_fmt_Z_timezone (test acs-lang) test_lc_time_fmt_Z_timezone->lc_time_fmt ad_conn ad_conn (public) lc_time_fmt->ad_conn lc_time_fmt_compile lc_time_fmt_compile (public) lc_time_fmt->lc_time_fmt_compile apm_build_repository apm_build_repository (private) apm_build_repository->lc_time_fmt calendar::item::get calendar::item::get (public) calendar::item::get->lc_time_fmt callback::search::action::impl::syndicate callback::search::action::impl::syndicate (public) callback::search::action::impl::syndicate->lc_time_fmt dt_ansi_to_pretty dt_ansi_to_pretty (public) dt_ansi_to_pretty->lc_time_fmt dt_get_info dt_get_info (private) dt_get_info->lc_time_fmt

Testcases:
lang_test__lc_numeric, lc_time_fmt_Z_timezone

lc_time_fmt_compile (public)

 lc_time_fmt_compile fmt locale

Compiles ISO 14652 LC_TIME style formatting string to variable substitions and proc calls.

Parameters:
fmt - An ISO 14652 LC_TIME style formatting string.
locale - Locale identifier must be in the locale database
Returns:
A string that should be subst'ed in the lc_time_fmt proc after local variables have been set.

Partial Call Graph (max 5 caller/called nodes):
%3 lc_time_fmt lc_time_fmt (public) lc_time_fmt_compile lc_time_fmt_compile lc_time_fmt->lc_time_fmt_compile lc_get lc_get (public) lc_time_fmt_compile->lc_get

Testcases:
No testcase defined.

lc_time_local_to_utc (public)

 lc_time_local_to_utc time_value [ tz ]

Converts a local time to a UTC time for the specified timezone.

Parameters:
time_value - Local time in the ISO datetime format, YYYY-MM-DD HH24:MI:SS
tz (optional) - Timezone that must exist in tz_data table.
Returns:
UTC time.

Partial Call Graph (max 5 caller/called nodes):
%3 test_lang_test__lc_numeric lang_test__lc_numeric (test acs-lang) lc_time_local_to_utc lc_time_local_to_utc test_lang_test__lc_numeric->lc_time_local_to_utc ad_log ad_log (public) lc_time_local_to_utc->ad_log ad_try ad_try (public) lc_time_local_to_utc->ad_try db_exec_plsql db_exec_plsql (public) lc_time_local_to_utc->db_exec_plsql calendar::item::get calendar::item::get (public) calendar::item::get->lc_time_local_to_utc packages/acs-lang/www/admin/test/test.tcl packages/acs-lang/ www/admin/test/test.tcl packages/acs-lang/www/admin/test/test.tcl->lc_time_local_to_utc packages/acs-lang/www/admin/test/timezone.tcl packages/acs-lang/ www/admin/test/timezone.tcl packages/acs-lang/www/admin/test/timezone.tcl->lc_time_local_to_utc

Testcases:
lang_test__lc_numeric

lc_time_system_to_conn (public)

 lc_time_system_to_conn time_value

Converts a date from the system (database) to the connection's timezone, using the OpenACS timezone setting and user's preference

Parameters:
time_value - Timestamp from the database in the ISO datetime format.
Returns:
Timestamp in conn's local time, also in ISO datetime format.

Partial Call Graph (max 5 caller/called nodes):
%3 calendar::item::get calendar::item::get (public) lc_time_system_to_conn lc_time_system_to_conn calendar::item::get->lc_time_system_to_conn forum::message::get forum::message::get (public) forum::message::get->lc_time_system_to_conn fs::get_folder_contents fs::get_folder_contents (public) fs::get_folder_contents->lc_time_system_to_conn packages/acs-templating/www/scripts/xinha/file-selector.tcl packages/acs-templating/ www/scripts/xinha/file-selector.tcl packages/acs-templating/www/scripts/xinha/file-selector.tcl->lc_time_system_to_conn packages/calendar/www/view-list-display.tcl packages/calendar/ www/view-list-display.tcl packages/calendar/www/view-list-display.tcl->lc_time_system_to_conn ad_conn ad_conn (public) lc_time_system_to_conn->ad_conn lc_time_tz_convert lc_time_tz_convert (public) lc_time_system_to_conn->lc_time_tz_convert

Testcases:
No testcase defined.

lc_time_tz_convert (public)

 lc_time_tz_convert -from from -to to -time_value time_value

Converts a date from one timezone to another.

Switches:
-from (required)
-to (required)
-time_value (required)
Timestamp in the 'from' timezone, in the ISO datetime format.
Returns:
Timestamp in the 'to' timezone, also in ISO datetime format.

Partial Call Graph (max 5 caller/called nodes):
%3 fs::rss::datasource fs::rss::datasource (private) lc_time_tz_convert lc_time_tz_convert fs::rss::datasource->lc_time_tz_convert lc_time_conn_to_system lc_time_conn_to_system (public) lc_time_conn_to_system->lc_time_tz_convert lc_time_system_to_conn lc_time_system_to_conn (public) lc_time_system_to_conn->lc_time_tz_convert news__rss_datasource news__rss_datasource (private) news__rss_datasource->lc_time_tz_convert rss_gen_200 rss_gen_200 (public) rss_gen_200->lc_time_tz_convert ad_log ad_log (public) lc_time_tz_convert->ad_log ad_try ad_try (public) lc_time_tz_convert->ad_try db_exec_plsql db_exec_plsql (public) lc_time_tz_convert->db_exec_plsql

Testcases:
No testcase defined.

lc_time_utc_to_local (public)

 lc_time_utc_to_local time_value [ tz ]

Converts a Universal Time to local time for the specified timezone.

Parameters:
time_value - UTC time in the ISO datetime format.
tz (optional) - Timezone that must exist in tz_data table.
Returns:
Local time

Partial Call Graph (max 5 caller/called nodes):
%3 test_lang_test__lc_numeric lang_test__lc_numeric (test acs-lang) lc_time_utc_to_local lc_time_utc_to_local test_lang_test__lc_numeric->lc_time_utc_to_local ad_log ad_log (public) lc_time_utc_to_local->ad_log ad_try ad_try (public) lc_time_utc_to_local->ad_try db_exec_plsql db_exec_plsql (public) lc_time_utc_to_local->db_exec_plsql packages/acs-lang/www/admin/test/test.tcl packages/acs-lang/ www/admin/test/test.tcl packages/acs-lang/www/admin/test/test.tcl->lc_time_utc_to_local packages/acs-lang/www/admin/test/timezone.tcl packages/acs-lang/ www/admin/test/timezone.tcl packages/acs-lang/www/admin/test/timezone.tcl->lc_time_utc_to_local

Testcases:
lang_test__lc_numeric
[ show source ]