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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1998-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%
%% File: y2k_SUITE.erl
%% Purpose: Year 2000 tests.
-module(y2k_SUITE).
-include_lib("test_server/include/test_server.hrl").
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
init_per_group/2,end_per_group/2,
date_1999_01_01/1, date_1999_02_28/1,
date_1999_09_09/1, date_2000_01_01/1,
date_2000_02_29/1, date_2001_01_01/1,
date_2001_02_29/1, date_2004_02_29/1
]).
suite() -> [{ct_hooks,[ts_install_cth]}].
all() ->
[date_1999_01_01, date_1999_02_28, date_1999_09_09,
date_2000_01_01, date_2000_02_29, date_2001_01_01,
date_2001_02_29, date_2004_02_29].
groups() ->
[].
init_per_suite(Config) ->
Config.
end_per_suite(_Config) ->
ok.
init_per_group(_GroupName, Config) ->
Config.
end_per_group(_GroupName, Config) ->
Config.
date_1999_01_01(doc) ->
"#1 : 1999-01-01: test roll-over from 1998-12-31 to 1999-01-01.";
date_1999_01_01(suite) ->
[];
date_1999_01_01(Config) when is_list(Config) ->
?line Date = {1998, 12, 31}, NextDate = {1999, 1, 1},
?line match(next_date(Date), NextDate),
TZD = tzd(Date),
if
TZD > 0 ->
?line Time = {24 - TZD, 0, 0},
?line {NDate, _NTime} =
erlang:localtime_to_universaltime({Date, Time}),
?line match(NDate, NextDate);
TZD < 0 ->
?line Time = {24 + TZD, 0, 0},
?line {NDate, _NTime} =
erlang:universaltime_to_localtime({Date, Time}),
?line match(NDate, NextDate);
true ->
ok
end.
date_1999_02_28(doc) ->
"#2 : 1999-02-28: test roll-over from 1999-02-28 to 1999-03-01.";
date_1999_02_28(suite) ->
[];
date_1999_02_28(Config) when is_list(Config) ->
?line Date = {1999, 2, 28}, NextDate = {1999, 3, 1},
?line match(next_date(Date), NextDate),
?line match(tz_next_date(Date), NextDate).
date_1999_09_09(doc) ->
"#3 : 1999-09-09: test roll-over from 1999-09-08 to 1999-09-09.";
date_1999_09_09(suite) ->
[];
date_1999_09_09(Config) when is_list(Config) ->
?line Date = {1999, 9, 8}, NextDate = {1999, 9, 9},
?line match(next_date(Date), NextDate),
?line match(tz_next_date(Date), NextDate).
date_2000_01_01(doc) ->
"#4 : 2000-01-01: test roll-over from 1999-12-31 to 2000-01-01 to "
"2000-01-02.";
date_2000_01_01(suite) ->
[];
date_2000_01_01(Config) when is_list(Config) ->
?line Date = {1999, 12, 31}, NextDate = {2000, 1, 1},
?line match(next_date(Date), NextDate),
?line match(tz_next_date(Date), NextDate),
?line NextDate1 = {2000, 1, 2},
?line match(next_date(NextDate), NextDate1),
?line match(tz_next_date(NextDate), NextDate1).
date_2000_02_29(doc) ->
"#5 : 2000-02-29: test roll-over from 2000-02-28 to 2000-02-29 to "
"2000-03-01.";
date_2000_02_29(suite) ->
[];
date_2000_02_29(Config) when is_list(Config) ->
?line Date = {2000, 2, 28}, NextDate = {2000, 2, 29},
?line match(next_date(Date), NextDate),
?line match(tz_next_date(Date), NextDate),
?line NextDate1 = {2000, 3, 1},
?line match(next_date(NextDate), NextDate1),
?line match(tz_next_date(NextDate), NextDate1).
date_2001_01_01(doc) ->
"#6 : 2001-01-01: test roll-over from 2000-12-31 to 2001-01-01.";
date_2001_01_01(suite) ->
[];
date_2001_01_01(Config) when is_list(Config) ->
?line Date = {2000, 12, 31}, NextDate = {2001, 1, 1},
?line match(next_date(Date), NextDate),
?line match(tz_next_date(Date), NextDate).
date_2001_02_29(doc) ->
"#7 : 2001-02-29: test roll-over from 2001-02-28 to 2001-03-01.";
date_2001_02_29(suite) ->
[];
date_2001_02_29(Config) when is_list(Config) ->
?line Date = {2001, 2, 28}, NextDate = {2001, 3, 1},
?line match(next_date(Date), NextDate),
?line match(tz_next_date(Date), NextDate).
date_2004_02_29(doc) ->
"#8 : 2004-02-29: test roll-over from 2004-02-28 to 2004-02-29 to "
"2004-03-01.";
date_2004_02_29(suite) ->
[];
date_2004_02_29(Config) when is_list(Config) ->
?line Date = {2004, 2, 28}, NextDate = {2004, 2, 29},
?line match(next_date(Date), NextDate),
?line match(tz_next_date(Date), NextDate),
?line NextDate1 = {2004, 3, 1},
?line match(next_date(NextDate), NextDate1),
?line match(tz_next_date(NextDate), NextDate1).
%%
%% Local functions
%%
next_date(Date) ->
calendar:gregorian_days_to_date(calendar:date_to_gregorian_days(Date) + 1).
%%
%% timezonediff
%%
tzd(Date) ->
?line {_LDate, {LH, _LM, _LS}} =
erlang:universaltime_to_localtime({Date, {12, 0, 0}}),
12 - LH.
tz_next_date(Date) ->
TZD = tzd(Date),
if
TZD > 0 ->
?line Time = {24 - TZD, 0, 0},
?line {NDate, _NTime} =
erlang:localtime_to_universaltime({Date, Time}),
?line NDate;
TZD < 0 ->
?line Time = {24 + TZD, 0, 0},
?line {NDate, _NTime} =
erlang:universaltime_to_localtime({Date, Time}),
?line NDate;
true ->
Date
end.
%%
%% match({X, X}) ->
%% ok.
match(X, X) ->
ok.
|