4
%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
4
%% Copyright Ericsson AB 1997-2010. All Rights Reserved.
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
19
19
-module(calendar_SUITE).
21
-include("test_server.hrl").
21
-include_lib("test_server/include/test_server.hrl").
23
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
24
init_per_group/2,end_per_group/2,
25
26
gregorian_seconds/1,
27
28
day_of_the_week_calibrate/1,
29
30
last_day_of_the_month/1,
30
local_time_to_universal_time_dst/1]).
31
local_time_to_universal_time_dst/1,
32
34
-define(START_YEAR, 1947).
33
35
-define(END_YEAR, 2012).
35
all(suite) -> [gregorian_days,
38
day_of_the_week_calibrate,
40
last_day_of_the_month,
41
local_time_to_universal_time_dst];
43
all(doc) -> "This is the test suite for calendar.erl".
37
suite() -> [{ct_hooks,[ts_install_cth]}].
40
[gregorian_days, gregorian_seconds, day_of_the_week,
41
day_of_the_week_calibrate, leap_years,
42
last_day_of_the_month, local_time_to_universal_time_dst, iso_week_number].
47
init_per_suite(Config) ->
50
end_per_suite(_Config) ->
53
init_per_group(_GroupName, Config) ->
56
end_per_group(_GroupName, Config) ->
45
59
gregorian_days(doc) ->
46
60
"Tests that date_to_gregorian_days and gregorian_days_to_date "
48
62
"At the same time valid_date is tested.";
49
63
gregorian_days(suite) ->
51
gregorian_days(Config) when list(Config) ->
65
gregorian_days(Config) when is_list(Config) ->
52
66
?line Days = calendar:date_to_gregorian_days({?START_YEAR, 1, 1}),
53
67
?line MaxDays = calendar:date_to_gregorian_days({?END_YEAR, 1, 1}),
54
68
?line check_gregorian_days(Days, MaxDays).
60
74
"every 2 days + 1 second.";
61
75
gregorian_seconds(suite) ->
63
gregorian_seconds(Config) when list(Config) ->
77
gregorian_seconds(Config) when is_list(Config) ->
64
78
?line Secs = calendar:datetime_to_gregorian_seconds({{?START_YEAR, 1, 1},
66
80
?line MaxSecs = calendar:datetime_to_gregorian_seconds({{?END_YEAR, 1, 1},
72
86
"year ?START_YEAR up to ?END_YEAR.";
73
87
day_of_the_week(suite) ->
75
day_of_the_week(Config) when list(Config) ->
89
day_of_the_week(Config) when is_list(Config) ->
76
90
?line Days = calendar:date_to_gregorian_days({?START_YEAR, 1, 1}),
77
91
?line MaxDays = calendar:date_to_gregorian_days({?END_YEAR, 1, 1}),
78
92
?line DayNumber = calendar:day_of_the_week({?START_YEAR, 1, 1}),
82
96
"Tests that day_of_the_week for 1997-11-11 is Tuesday (2)";
83
97
day_of_the_week_calibrate(suite) ->
85
day_of_the_week_calibrate(Config) when list(Config) ->
99
day_of_the_week_calibrate(Config) when is_list(Config) ->
86
100
?line 2 = calendar:day_of_the_week({1997, 11, 11}).
88
102
leap_years(doc) ->
90
104
"year ?START_YEAR up to ?END_YEAR.";
91
105
leap_years(suite) ->
93
leap_years(Config) when list(Config) ->
107
leap_years(Config) when is_list(Config) ->
94
108
?line check_leap_years(?START_YEAR, ?END_YEAR).
96
110
last_day_of_the_month(doc) ->
98
112
"year ?START_YEAR up to ?END_YEAR.";
99
113
last_day_of_the_month(suite) ->
101
last_day_of_the_month(Config) when list(Config) ->
115
last_day_of_the_month(Config) when is_list(Config) ->
102
116
?line check_last_day_of_the_month({?START_YEAR, 1}, {?END_YEAR, 1}).
104
118
local_time_to_universal_time_dst(doc) ->
105
119
"Tests local_time_to_universal_time_dst for MET";
106
120
local_time_to_universal_time_dst(suite) ->
108
local_time_to_universal_time_dst(Config) when list(Config) ->
122
local_time_to_universal_time_dst(Config) when is_list(Config) ->
109
123
case os:type() of
111
125
case os:cmd("date '+%Z'") of
118
132
local_time_to_universal_time_dst_x(Config)
120
local_time_to_universal_time_dst_x(Config) when list(Config) ->
134
local_time_to_universal_time_dst_x(Config) when is_list(Config) ->
121
135
%% Assumes MET (UTC+1 / UTC+2(dst)
122
136
?line LtW = {{2003,01,15},{14,00,00}}, % Winter
123
137
?line UtW = {{2003,01,15},{13,00,00}}, %
156
170
{comment,"Bug in mktime() in this OS"}
173
iso_week_number(doc) ->
174
"Test the iso week number calculation for all three possibilities."
175
" When the date falls on the last week of the previous year,"
176
" when the date falls on a week within the given year and finally,"
177
" when the date falls on the first week of the next year.";
178
iso_week_number(suite) ->
180
iso_week_number(Config) when is_list(Config) ->
181
?line check_iso_week_number().
161
184
%% LOCAL FUNCTIONS
245
268
check_last_day_of_the_month(_, _) ->
271
%% check_iso_week_number
273
check_iso_week_number() ->
274
?line {2004, 53} = calendar:iso_week_number({2005, 1, 1}),
275
?line {2007, 1} = calendar:iso_week_number({2007, 1, 1}),
276
?line {2009, 1} = calendar:iso_week_number({2008, 12, 29}).