Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
cee705be45 | ||
![]() |
9833becbb6 | ||
![]() |
b97f2432ce | ||
![]() |
95c44085d9 | ||
![]() |
3127dcddfb | ||
![]() |
cf9e726d1b | ||
![]() |
13c44576ac | ||
![]() |
28ea9f254f |
12 changed files with 64 additions and 29 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ _build/
|
||||||
*~
|
*~
|
||||||
src/tz_index.erl
|
src/tz_index.erl
|
||||||
*.sw?
|
*.sw?
|
||||||
|
rebar3
|
||||||
|
|
23
Makefile
23
Makefile
|
@ -1,11 +1,26 @@
|
||||||
all:
|
all: rebar3
|
||||||
./rebar3 compile
|
./rebar3 compile
|
||||||
|
|
||||||
check:
|
check: rebar3
|
||||||
./rebar3 eunit
|
./rebar3 eunit
|
||||||
|
|
||||||
dialyzer:
|
test: check
|
||||||
|
|
||||||
|
dialyzer: rebar3
|
||||||
./rebar3 dialyzer
|
./rebar3 dialyzer
|
||||||
|
|
||||||
publish:
|
publish: rebar3
|
||||||
./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)
|
||||||
|
|
24
README.md
24
README.md
|
@ -1,21 +1,21 @@
|
||||||
## NOTE
|
## NOTE
|
||||||
|
|
||||||
This is a fork of
|
This is a fork of the excellent library,
|
||||||
[erlang_localtime](https://github.com/dmitryme/erlang_localtime), modified
|
[erlang_localtime](https://github.com/dmitryme/erlang_localtime). The purpose
|
||||||
specifically for compatibility with
|
of this fork is 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 a bit over the years. The qdate tests will not pass if the
|
but have diverged slightly over the years. The qdate tests will not pass if the
|
||||||
original erlang_localtime dependency is used due to some subtle differences to
|
original `erlang_localtime dependency` is used due to some subtle differences
|
||||||
attempt to make qdate a little bit smarter.
|
to 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:
|
||||||
|
|
|
@ -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.
|
||||||
%% Rounded timezone rules of Asia/Tehran to week 3 in march and september
|
%% Removed DST from Iran and Asia/Tehran
|
||||||
|
|
||||||
{"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"},{"IRDT","IRDT"},210,60,{3,sat,mar},{0,0},{3,sat,sep},{0,0}},
|
{"Asia/Tehran",{"IRST","IRST"},undef,210,0,undef,{0,0},undef,{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"},{"IRDT","IRDT"},210,60,undef,{0,0},undef,{0,0}},
|
{"Iran",{"IRST","IRST"},undef,210,0,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
Normal file
3
priv/db/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
tzout
|
||||||
|
tzdata/
|
||||||
|
*.tar.gz
|
|
@ -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=`perl -n -e 'm/^VERSION\s*=\s*(\S+)/ and print $$1;' $(TZDIR)/Makefile`; \
|
TZ_VERSION=`cat $(TZDIR)/version`; \
|
||||||
./tz-erl --version $$TZ_VERSION --date $(DATE) -o $@ $^
|
./tz-erl --version $$TZ_VERSION --date $(DATE) -o $@ $^
|
||||||
|
|
||||||
$(TZ_FILES): $(TZDIR)
|
$(TZ_FILES): $(TZDIR)
|
||||||
|
@ -14,4 +14,5 @@ $(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 *~)
|
|
@ -459,11 +459,16 @@ 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.
|
||||||
|
@ -472,7 +477,12 @@ 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];
|
||||||
if ($dow != $desired_dow) { $day += (DPW + $desired_dow - $dow) % DPW; }
|
print "Current Day: $day\n";
|
||||||
|
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;
|
||||||
|
@ -511,6 +521,10 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 +0,0 @@
|
||||||
[].
|
|
BIN
rebar3
BIN
rebar3
Binary file not shown.
|
@ -256,9 +256,11 @@ tr_char_test() ->
|
||||||
|
|
||||||
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")).
|
||||||
|
|
|
@ -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.0"},
|
{vsn, "1.2.1"},
|
||||||
{applications, [kernel, stdlib]},
|
{applications, [kernel, stdlib]},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue