Skip to content

Commit

Permalink
Do not discard previously parsed date when applying %r directive (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
sparta-developers authored and bitwalker committed Aug 8, 2018
1 parent f2335e0 commit 97dcc4d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/parse/datetime/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,13 @@ defmodule Timex.Parse.DateTime.Parser do
case token do
# Formats
clock when clock in [:kitchen, :strftime_iso_kitchen] ->
{{y,m,d},_} = :calendar.universal_time()
date = %{date | :year => y, :month => m, :day => d}
date = cond do
date == Timex.DateTime.Helpers.empty() ->
{{y,m,d},_} = :calendar.universal_time()
%{date | :year => y, :month => m, :day => d}
true ->
date
end
case apply_directives(value, date, tokenizer) do
{:error, _} = err -> err
{:ok, date} when clock == :kitchen ->
Expand Down
19 changes: 19 additions & 0 deletions test/parse_strftime_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ defmodule DateFormatTest.ParseStrftime do
assert elem(ms3.microsecond, 0) == 100 * 1_000
end

test "issue #446 - strftime_iso_kitchen should not discard dates" do
input_datetime_str = "July 23, 2018 05:34:04 PM PDT"
expected_datetime = %DateTime{
calendar: Calendar.ISO,
day: 23,
hour: 17,
microsecond: {0, 0},
minute: 34,
month: 7,
second: 4,
std_offset: 3600,
time_zone: "PST8PDT",
utc_offset: -28800,
year: 2018,
zone_abbr: "PDT"
}
assert Timex.parse!(input_datetime_str, "%B %d, %Y %r %Z", :strftime) == expected_datetime
end

defp parse(date, fmt) do
Timex.parse(date, fmt, :strftime)
end
Expand Down

0 comments on commit 97dcc4d

Please sign in to comment.