diff options
author | Sverker Eriksson <[email protected]> | 2013-10-16 15:44:16 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2013-10-16 15:44:16 +0200 |
commit | cd551998b4ea3fb7945e35164486c2aefd71e045 (patch) | |
tree | 6291fe4884db909aa4031d2dc50e492d399b806e | |
parent | 21270f86ab03d976ce3137c84d21e43ce6bc404b (diff) | |
parent | 4d4a2170a02b5550df4ba3a7c04a755523b81cb4 (diff) | |
download | otp-cd551998b4ea3fb7945e35164486c2aefd71e045.tar.gz otp-cd551998b4ea3fb7945e35164486c2aefd71e045.tar.bz2 otp-cd551998b4ea3fb7945e35164486c2aefd71e045.zip |
Merge branch 'maint'
-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. %% |