/
i18n_calendar.erl
72 lines (55 loc) · 2.22 KB
/
i18n_calendar.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
% vim: set filetype=erlang shiftwidth=4 tabstop=4 expandtab tw=80:
%%% =====================================================================
%%% Copyright 2011 Uvarov Michael
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
%%% You may obtain a copy of the License at
%%%
%%% http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing, software
%%% distributed under the License is distributed on an "AS IS" BASIS,
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%%% See the License for the specific language governing permissions and
%%% limitations under the License.
%%%
%%% $Id$
%%%
%%% @copyright 2010-2011 Michael Uvarov
%%% @author Michael Uvarov <arcusfelis@gmail.com>
%%% =====================================================================
-module(i18n_calendar).
-include("i18n.hrl").
-export([open/0, open/1, open/2, open/3]).
-export([available_locales/0, available_timezones/0]).
-type i18n_locale_id() :: atom().
-type i18n_string() :: binary().
-type resource() :: <<>>.
-type i18n_calendar() :: resource().
-type i18n_timezone() :: atom() | i18n_string().
-type i18n_calendar_type() :: 'gregorian' | 'traditional'.
-spec open() -> i18n_calendar().
open() ->
Locale = i18n_locale:get_locale(),
open(Locale).
-spec open(i18n_locale_id()) -> i18n_calendar().
open(Locale) ->
?TRY_RES(?IM:open_calendar(Locale)).
-spec open(i18n_locale_id(), i18n_timezone()) -> i18n_calendar().
open(Locale, TZ) when is_atom(TZ) ->
?TRY_RES(?IM:open_calendar(Locale, i18n_string:from(TZ)));
open(Locale, TZ) ->
?TRY_RES(?IM:open_calendar(Locale, TZ)).
-spec open(i18n_locale_id(), i18n_timezone(), i18n_calendar_type()) ->
i18n_calendar().
open(Locale, TZ, Type) when is_atom(TZ) ->
?TRY_RES(?IM:open_calendar(Locale, i18n_string:from(TZ), Type));
open(Locale, TZ, Type) ->
?TRY_RES(?IM:open_calendar(Locale, TZ, Type)).
-spec available_locales() -> [i18n_locale_id()].
available_locales() ->
?TRY_LIST(?IM:calendar_locales()).
-spec available_timezones() -> [i18n_timezone()].
available_timezones() ->
?TRY_LIST(?IM:timezone_ids()).