Compare commits

..

1 commit

Author SHA1 Message Date
Jesse Gumm
f7b865e329 Fix windows slash in rebar.config 2021-07-01 08:46:14 -05:00
12 changed files with 29 additions and 64 deletions

1
.gitignore vendored
View file

@ -3,4 +3,3 @@ _build/
*~ *~
src/tz_index.erl src/tz_index.erl
*.sw? *.sw?
rebar3

View file

@ -1,26 +1,11 @@
all: rebar3 all:
./rebar3 compile ./rebar3 compile
check: rebar3 check:
./rebar3 eunit ./rebar3 eunit
test: check dialyzer:
dialyzer: rebar3
./rebar3 dialyzer ./rebar3 dialyzer
publish: rebar3 publish:
./rebar3 hex publish ./rebar3 hex publish
rebar3:
@(echo "Building rebar3...")
@(rm -fr tmp)
@(mkdir -p tmp)
@(cd tmp && \
git clone https://github.com/erlang/rebar3 && \
cd rebar3 && \
./bootstrap)
@(echo "Moving rebar3 executable locally (NOT installing system-wide)")
@(mv tmp/rebar3/rebar3 .)
@(echo "Cleaning up rebar3 remnants")
@(rm -fr tmp)

View file

@ -1,21 +1,21 @@
## NOTE ## NOTE
This is a fork of the excellent library, This is a fork of
[erlang_localtime](https://github.com/dmitryme/erlang_localtime). The purpose [erlang_localtime](https://github.com/dmitryme/erlang_localtime), modified
of this fork is specifically for compatibility with specifically for compatibility with
[qdate](https://github.com/choptastic/qdate). The two are mostly compatible, [qdate](https://github.com/choptastic/qdate). The two are mostly compatible,
but have diverged slightly over the years. The qdate tests will not pass if the but have diverged a bit over the years. The qdate tests will not pass if the
original `erlang_localtime dependency` is used due to some subtle differences original erlang_localtime dependency is used due to some subtle differences to
to attempt to make qdate a little bit smarter. attempt to make qdate a little bit smarter.
#### Public exports #### Public exports
* `utc_to_local(DateTime, Timezone)` - converts UTC time to local according to specified Timezone * utc_to_local(DateTime, Timezone) - converts UTC time to local according to specified Timezone
* `local_to_utc(DateTime, Timezone)` - converts local time to UTC * local_to_utc(DateTime, Timezone) - converts local time to UTC
* `local_to_local(DateTime, TimezoneFrom, TimezoneTo)` - converts local time to local * local_to_local(DateTime, TimezoneFrom, TimezoneTo) - converts local time to local
* `tz_name(DateTime, Timezone)` - returns a timezone name (E.g. MSK, MSD, etc) * tz_name(DateTime, Timezone) - returns a timezone name (E.g. MSK, MSD, etc)
* `tz_shift(DateTime, Timezone)` - returns time difference between local datetime and GMT * tz_shift(DateTime, Timezone) - returns time difference between local datetime and GMT
* `tz_shift(DateTime, TimezoneFrom, TimezoneTo)` - returns time difference between local datetime and required timezone * tz_shift(DateTime, TimezoneFrom, TimezoneTo) - returns time difference between local datetime and required timezone
Where Where
DateTime = {date(), time()} DateTime = {date(), time()}
TimeZone(To, From) = String(). E.g. “Europe/Moscow”, “America/NewYork”. Or abbreviations "MSK", "MSD", etc. Note: TimeZone(To, From) = String(). E.g. “Europe/Moscow”, “America/NewYork”. Or abbreviations "MSK", "MSD", etc. Note:

View file

@ -3,7 +3,7 @@ TZ_FILES=$(addprefix $(TZDIR)/, africa antarctica asia australasia backward etce
tzout: DATE := $(shell date +%F) tzout: DATE := $(shell date +%F)
tzout: $(TZ_FILES) tzout: $(TZ_FILES)
TZ_VERSION=`cat $(TZDIR)/version`; \ TZ_VERSION=`perl -n -e 'm/^VERSION\s*=\s*(\S+)/ and print $$1;' $(TZDIR)/Makefile`; \
./tz-erl --version $$TZ_VERSION --date $(DATE) -o $@ $^ ./tz-erl --version $$TZ_VERSION --date $(DATE) -o $@ $^
$(TZ_FILES): $(TZDIR) $(TZ_FILES): $(TZDIR)
@ -14,5 +14,4 @@ $(TZDIR): tzdata-latest.tar.gz
tzdata-latest.tar.gz: tzdata-latest.tar.gz:
curl -O "ftp://ftp.iana.org/tz/tzdata-latest.tar.gz" curl -O "ftp://ftp.iana.org/tz/tzdata-latest.tar.gz"
clean:
@(rm -fr tzdata *.tar.gz tzout *~)

View file

@ -459,16 +459,11 @@ sub on_to_day_of_month {
my $day; my $day;
if ($on =~ m/^\d+$/) { if ($on =~ m/^\d+$/) {
$day = $on; $day = $on;
print "Day extracted via regex to: $day\n";
} else { } else {
my ($desired_dow, $time_base); my ($desired_dow, $time_base);
if ($on =~ m/^(\w+)>=(\d+)$/) { if ($on =~ m/^(\w+)>=(\d+)$/) {
$desired_dow = $dow_from_name{$1}; my $desired_day = $2; $desired_dow = $dow_from_name{$1}; my $desired_day = $2;
$time_base = timelocal(0, 0, 0, $desired_day, $month, $year); $time_base = timelocal(0, 0, 0, $desired_day, $month, $year);
print "Regex: $on => desired_dow: $desired_dow. Time_base: $time_base\n";
} elsif ($on =~ m/^(\w+)<=(\d+)$/) {
$desired_dow = $dow_from_name{$1}; my $desired_day = $2;
$time_base = timelocal(0, 0, 0, $desired_day, $month, $year);
} elsif ($on =~ m/^last(\w+)$/) { } elsif ($on =~ m/^last(\w+)$/) {
$desired_dow = $dow_from_name{$1}; $desired_dow = $dow_from_name{$1};
# One week before the beginning of the next month. # One week before the beginning of the next month.
@ -477,12 +472,7 @@ sub on_to_day_of_month {
die "match $on failed"; die "match $on failed";
} }
($day, my $dow) = (localtime($time_base))[3,6]; ($day, my $dow) = (localtime($time_base))[3,6];
print "Current Day: $day\n"; if ($dow != $desired_dow) { $day += (DPW + $desired_dow - $dow) % DPW; }
print "Comparing $dow = $desired_dow\n";
if ($dow != $desired_dow) {
$day += (DPW + $desired_dow - $dow) % DPW;
}
print "After comparison: Current Day: $day\n";
} }
return $day; return $day;
@ -521,10 +511,6 @@ sub last_active_epoch {
} }
my $day = on_to_day_of_month($on, $year, $month); my $day = on_to_day_of_month($on, $year, $month);
print "On=$on, Year=$year, Month=$month ====> Day=$day\n";
## changing the below call to timelocal_nocheck stops the crash, but it feels wrong
## especially since without it, it seems to produce a lot of "redundant" error messages
## I don't have time to explore this now, but I'll come back to it
return timelocal(0, 0, 0, $day, $month, $year); return timelocal(0, 0, 0, $day, $month, $year);
} }

View file

@ -35,7 +35,7 @@
%% Discarded excess rules for Zone Africa/El_Aaiun. %% Discarded excess rules for Zone Africa/El_Aaiun.
%% Moving rule to beginning of day for Zone America/Godthab. %% Moving rule to beginning of day for Zone America/Godthab.
%% Moving rule to beginning of day for Zone America/Godthab. %% Moving rule to beginning of day for Zone America/Godthab.
%% Removed DST from Iran and Asia/Tehran %% Rounded timezone rules of Asia/Tehran to week 3 in march and september
{"Africa/Abidjan",{"GMT","GMT"},undef,0,0,undef,{0,0},undef,{0,0}}, {"Africa/Abidjan",{"GMT","GMT"},undef,0,0,undef,{0,0},undef,{0,0}},
{"Africa/Accra",{"GMT","GMT"},undef,0,0,undef,{0,0},undef,{0,0}}, {"Africa/Accra",{"GMT","GMT"},undef,0,0,undef,{0,0},undef,{0,0}},
@ -347,7 +347,7 @@
{"Asia/Taipei",{"CST","CST"},undef,480,0,undef,{0,0},undef,{0,0}}, {"Asia/Taipei",{"CST","CST"},undef,480,0,undef,{0,0},undef,{0,0}},
{"Asia/Tashkent",{"UZT","UZT"},undef,300,0,undef,{0,0},undef,{0,0}}, {"Asia/Tashkent",{"UZT","UZT"},undef,300,0,undef,{0,0},undef,{0,0}},
{"Asia/Tbilisi",{"GET","GET"},undef,240,0,undef,{0,0},undef,{0,0}}, {"Asia/Tbilisi",{"GET","GET"},undef,240,0,undef,{0,0},undef,{0,0}},
{"Asia/Tehran",{"IRST","IRST"},undef,210,0,undef,{0,0},undef,{0,0}}, {"Asia/Tehran",{"IRST","IRST"},{"IRDT","IRDT"},210,60,{3,sat,mar},{0,0},{3,sat,sep},{0,0}},
{"Asia/Tel_Aviv",{"IST","IST"},{"IDT","IDT"},120,60,{4,fri,mar},{2,0},{last,sun,oct},{2,0}}, {"Asia/Tel_Aviv",{"IST","IST"},{"IDT","IDT"},120,60,{4,fri,mar},{2,0},{last,sun,oct},{2,0}},
{"Asia/Thimbu",{"BTT","BTT"},undef,360,0,undef,{0,0},undef,{0,0}}, {"Asia/Thimbu",{"BTT","BTT"},undef,360,0,undef,{0,0},undef,{0,0}},
{"Asia/Thimphu",{"BTT","BTT"},undef,360,0,undef,{0,0},undef,{0,0}}, {"Asia/Thimphu",{"BTT","BTT"},undef,360,0,undef,{0,0},undef,{0,0}},
@ -535,7 +535,7 @@
{"Indian/Mauritius",{"MUT","MUT"},undef,240,0,undef,{0,0},undef,{0,0}}, {"Indian/Mauritius",{"MUT","MUT"},undef,240,0,undef,{0,0},undef,{0,0}},
{"Indian/Mayotte",{"EAT","EAT"},undef,180,0,undef,{0,0},undef,{0,0}}, {"Indian/Mayotte",{"EAT","EAT"},undef,180,0,undef,{0,0},undef,{0,0}},
{"Indian/Reunion",{"RET","RET"},undef,240,0,undef,{0,0},undef,{0,0}}, {"Indian/Reunion",{"RET","RET"},undef,240,0,undef,{0,0},undef,{0,0}},
{"Iran",{"IRST","IRST"},undef,210,0,undef,{0,0},undef,{0,0}}, {"Iran",{"IRST","IRST"},{"IRDT","IRDT"},210,60,undef,{0,0},undef,{0,0}},
{"Israel",{"IST","IST"},{"IDT","IDT"},120,60,{4,fri,mar},{2,0},{last,sun,oct},{2,0}}, {"Israel",{"IST","IST"},{"IDT","IDT"},120,60,{4,fri,mar},{2,0},{last,sun,oct},{2,0}},
{"Jamaica",{"EST","EST"},undef,-300,0,undef,{0,0},undef,{0,0}}, {"Jamaica",{"EST","EST"},undef,-300,0,undef,{0,0},undef,{0,0}},
{"Japan",{"JST","JST"},undef,540,0,undef,{0,0},undef,{0,0}}, {"Japan",{"JST","JST"},undef,540,0,undef,{0,0},undef,{0,0}},

3
priv/db/.gitignore vendored
View file

@ -1,3 +0,0 @@
tzout
tzdata/
*.tar.gz

View file

@ -6,6 +6,6 @@
{pre_hooks,[ {pre_hooks,[
{"linux|bsd|darwin|solaris", compile, "priv/ibuild.escript"}, {"linux|bsd|darwin|solaris", compile, "priv/ibuild.escript"},
{"win32", compile, "escript.exe priv/ibuild.escript"} {"win32", compile, "escript.exe priv\\ibuild.escript"}
]}. ]}.

1
rebar.lock Normal file
View file

@ -0,0 +1 @@
[].

BIN
rebar3 Executable file

Binary file not shown.

View file

@ -255,12 +255,10 @@ tr_char_test() ->
?assertEqual("A_C_E", tr_char("A C E", ?SPACE_CHAR, $_)). ?assertEqual("A_C_E", tr_char("A C E", ?SPACE_CHAR, $_)).
tz_name_test() -> tz_name_test() ->
?assertEqual({"CET", "CET"}, tz_name({{2008,12,10},{15,30,0}}, "Europe/Amsterdam")), ?assertEqual({"CET", "CET"}, tz_name({{2008,12,10},{15,30,0}}, "Europe/Amsterdam")),
%%% No DST in Iran ?assertEqual({"IRST", "IRST"}, tz_name({{2008,12,10},{15,30,0}}, "Asia/Tehran")),
?assertEqual({"IRST", "IRST"}, tz_name({{2008,12,10},{15,30,0}}, "Asia/Tehran")), ?assertEqual({"IRDT", "IRDT"}, tz_name({{2020,5,4},{15,30,0}}, "Asia/Tehran")).
?assertEqual({"IRST", "IRST"}, tz_name({{2020,5,4},{15,30,0}}, "Asia/Tehran")),
?assertEqual({"IRST", "IRST"}, tz_name({{2008,12,10},{15,30,0}}, "Iran")),
?assertEqual({"IRST", "IRST"}, tz_name({{2020,5,4},{15,30,0}}, "Iran")).
get_timezone_test() -> get_timezone_test() ->
?assertEqual("America/Los_Angeles", get_timezone("America/Los Angeles")). ?assertEqual("America/Los_Angeles", get_timezone("America/Los Angeles")).

View file

@ -1,7 +1,7 @@
{application, 'qdate_localtime', {application, 'qdate_localtime',
[ [
{description, "Erlang library for conversion from one local time to another (forked specifically for qdate compatibility)"}, {description, "Erlang library for conversion from one local time to another (forked specifically for qdate compatibility)"},
{vsn, "1.2.1"}, {vsn, "1.2.0"},
{applications, [kernel, stdlib]}, {applications, [kernel, stdlib]},
{modules, []}, {modules, []},
{registered, []}, {registered, []},