diff options
author | Sverker Eriksson <[email protected]> | 2013-10-01 15:33:28 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2013-10-01 15:33:28 +0200 |
commit | f2a7538022e6d094bfbb003718fec688d3ba189e (patch) | |
tree | ced7695ada9b7b4b96490985165817b1967da659 | |
parent | e0ecc86e35475b434efa6cccba44074ca1040b7a (diff) | |
download | otp-f2a7538022e6d094bfbb003718fec688d3ba189e.tar.gz otp-f2a7538022e6d094bfbb003718fec688d3ba189e.tar.bz2 otp-f2a7538022e6d094bfbb003718fec688d3ba189e.zip |
erts: Fix time_SUITE:consistency to work over turn of the month
-rw-r--r-- | erts/emulator/test/time_SUITE.erl | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/erts/emulator/test/time_SUITE.erl b/erts/emulator/test/time_SUITE.erl index 4d12e3449c..a0a8a9c42c 100644 --- a/erts/emulator/test/time_SUITE.erl +++ b/erts/emulator/test/time_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2011. All Rights Reserved. +%% Copyright Ericsson AB 1997-2013. 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 @@ -241,14 +241,26 @@ compare(Utc0, Local) -> %% Two linear times can be subtracted to give their difference %% in seconds. %% -%% XXX Limitations: The length of months and leap years are not -%% taken into account; thus a comparision of dates is only -%% valid if they are in the SAME month. +%% XXX Limitations: Simplified leap year calc will fail for 2100 :-) linear_time({{Year, Mon, Day}, {Hour, Min, Sec}}) -> - 86400*(366*Year + 31*(Mon-1) + (Day-1)) + + 86400*(year_to_days(Year) + month_to_days(Year,Mon) + (Day-1)) + 3600*Hour + 60*Min + Sec. +year_to_days(Year) -> + Year * 365 + (Year-1) div 4. + +month_to_days(Year, Mon) -> + DoM = [31,days_in_february(Year),31,30,31,30,31,31,30,31,30,31], + {PastMonths,_} = lists:split(Mon-1, DoM), + lists:sum(PastMonths). + +days_in_february(Year) -> + case (Year rem 4) of + 0 -> 29; + _ -> 28 + end. + %% This functions returns either the normal timezone or the %% the DST timezone, depending on the given UTC time. %% |