Use actual ISO8601 timestamps for masto API
Some checks are pending
ci/woodpecker/pr/woodpecker Pipeline is pending
Some checks are pending
ci/woodpecker/pr/woodpecker Pipeline is pending
Elixir uses an incompatible superset of ISO8601 that breaks some clients
This commit is contained in:
parent
b98fe4476c
commit
2ce4f96f6e
2 changed files with 18 additions and 3 deletions
|
@ -328,10 +328,17 @@ def date_to_asctime(date) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_masto_date(%NaiveDateTime{} = date) do
|
def to_masto_date(%NaiveDateTime{} = date) do
|
||||||
|
# NOTE: Elixir’s ISO 8601 format is a superset of the real standard
|
||||||
|
# It supports negative years for example.
|
||||||
|
# ISO8601 only supports years before 1583 with mutual agreement
|
||||||
|
if date.year < 1583 do
|
||||||
|
""
|
||||||
|
else
|
||||||
date
|
date
|
||||||
|> NaiveDateTime.to_iso8601()
|
|> NaiveDateTime.to_iso8601()
|
||||||
|> String.replace(~r/(\.\d+)?$/, ".000Z", global: false)
|
|> String.replace(~r/(\.\d+)?$/, ".000Z", global: false)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def to_masto_date(date) when is_binary(date) do
|
def to_masto_date(date) when is_binary(date) do
|
||||||
with {:ok, date} <- NaiveDateTime.from_iso8601(date) do
|
with {:ok, date} <- NaiveDateTime.from_iso8601(date) do
|
||||||
|
|
|
@ -498,6 +498,14 @@ test "removes microseconds from date (String)" do
|
||||||
test "returns empty string when date invalid" do
|
test "returns empty string when date invalid" do
|
||||||
assert Utils.to_masto_date("2015-01?23T23:50:07.123Z") == ""
|
assert Utils.to_masto_date("2015-01?23T23:50:07.123Z") == ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns empty string when date is before the introduction of the Gregorian Calendar" do
|
||||||
|
assert Utils.to_masto_date("0621-01-01T00:00:00Z") == ""
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns empty string when date is BCE" do
|
||||||
|
assert Utils.to_masto_date("-420-01-01T00:00:00Z") == ""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "maybe_notify_mentioned_recipients/2" do
|
describe "maybe_notify_mentioned_recipients/2" do
|
||||||
|
|
Loading…
Reference in a new issue