diff options
author | Sverker Eriksson <sverker@erlang.org> | 2013-10-16 15:41:47 +0200 |
---|---|---|
committer | Sverker Eriksson <sverker@erlang.org> | 2013-10-16 15:41:47 +0200 |
commit | 4d4a2170a02b5550df4ba3a7c04a755523b81cb4 (patch) | |
tree | 3a24124b597d4c79d779ba62c80ec087acc32d42 /erts | |
parent | 356c1e9312a640ac211b6d5d4110372742acfcde (diff) | |
parent | f2a7538022e6d094bfbb003718fec688d3ba189e (diff) | |
download | otp-4d4a2170a02b5550df4ba3a7c04a755523b81cb4.tar.gz otp-4d4a2170a02b5550df4ba3a7c04a755523b81cb4.tar.bz2 otp-4d4a2170a02b5550df4ba3a7c04a755523b81cb4.zip |
Merge branch 'sverk/time-consistency-test' into maint
* sverk/time-consistency-test:
erts: Fix time_SUITE:consistency to work over turn of the month
Diffstat (limited to 'erts')
-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. %% |