diff --git a/.gitignore b/.gitignore index b4bcb39..1fcd342 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ _build/ *~ src/tz_index.erl *.sw? +rebar3 diff --git a/Makefile b/Makefile index 7ddd15e..f76d31c 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,24 @@ -all: +all: rebar3 ./rebar3 compile -check: +check: rebar3 ./rebar3 eunit -dialyzer: +dialyzer: rebar3 ./rebar3 dialyzer -publish: +publish: rebar3 ./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) diff --git a/README.md b/README.md index 19144ca..6e69541 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,21 @@ ## NOTE -This is a fork of -[erlang_localtime](https://github.com/dmitryme/erlang_localtime), modified -specifically for compatibility with +This is a fork of the excellent library, +[erlang_localtime](https://github.com/dmitryme/erlang_localtime). The purpose +of this fork is specifically for compatibility with [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 -original erlang_localtime dependency is used due to some subtle differences to -attempt to make qdate a little bit smarter. +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 attempt to make qdate a little bit smarter. #### Public exports -* 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_local(DateTime, TimezoneFrom, TimezoneTo) - converts local time to local -* 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, TimezoneFrom, TimezoneTo) - returns time difference between local datetime and required 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_local(DateTime, TimezoneFrom, TimezoneTo)` - converts local time to local +* `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, TimezoneFrom, TimezoneTo)` - returns time difference between local datetime and required timezone Where DateTime = {date(), time()} TimeZone(To, From) = String(). E.g. “Europe/Moscow”, “America/NewYork”. Or abbreviations "MSK", "MSD", etc. Note: diff --git a/db/tz-erl b/db/tz-erl index 3f41e21..ad21bd4 100755 --- a/db/tz-erl +++ b/db/tz-erl @@ -459,11 +459,16 @@ sub on_to_day_of_month { my $day; if ($on =~ m/^\d+$/) { $day = $on; + print "Day extracted via regex to: $day\n"; } else { my ($desired_dow, $time_base); if ($on =~ m/^(\w+)>=(\d+)$/) { $desired_dow = $dow_from_name{$1}; my $desired_day = $2; $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+)$/) { $desired_dow = $dow_from_name{$1}; # One week before the beginning of the next month. @@ -472,7 +477,12 @@ sub on_to_day_of_month { die "match $on failed"; } ($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; @@ -511,6 +521,7 @@ sub last_active_epoch { } my $day = on_to_day_of_month($on, $year, $month); - return timelocal(0, 0, 0, $day, $month, $year); + print "On=$on, Year=$year, Month=$month ====> Day=$day\n"; + return timelocal_nocheck(0, 0, 0, $day, $month, $year); } diff --git a/rebar.lock b/rebar.lock deleted file mode 100644 index 57afcca..0000000 --- a/rebar.lock +++ /dev/null @@ -1 +0,0 @@ -[]. diff --git a/rebar3 b/rebar3 deleted file mode 100755 index 6f0ccfa..0000000 Binary files a/rebar3 and /dev/null differ