Last active
January 5, 2017 16:24
-
-
Save bglusman/ef121631b9c7e77fd7dc553514e0ebbe to your computer and use it in GitHub Desktop.
date_string_or_error attempt, not working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def modified_date_or_datetime(string, modifier) do | |
date_match = Date.from_iso8601(string) | |
iso_match = Timex.parse(string, "{ISO:Extended}") | |
isoz_match = Timex.parse(string, "{ISO:Extended:Z}") | |
case {:ok, x } do | |
^date_match -> "#{string}#{modifier}" | |
^iso_match -> string | |
^isoz_match -> string | |
_ -> raise "Invalid ISO8601 date/datetime format provided: #{string}" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def modified_date_or_datetime(string, modifier) do | |
cond do | |
{:ok, _parsed_date} = Date.from_iso8601(string) -> "#{string}#{modifier}" | |
{:ok, _parsed_datetime} = Timex.parse(string, "{ISO:Extended}") -> string | |
{:ok, _parsed_datetime} = Timex.parse(string, "{ISO:Extended:Z}") -> string | |
true -> raise "Invalid ISO8601 date/datetime format provided: #{string}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment