Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server) - add publish date #58

Merged
merged 2 commits into from
Dec 29, 2024
Merged

fix(server) - add publish date #58

merged 2 commits into from
Dec 29, 2024

Conversation

dnkbln
Copy link
Contributor

@dnkbln dnkbln commented Dec 28, 2024

Übertragung des Release Dates

@dnkbln dnkbln requested a review from eteubert December 28, 2024 14:43
@eteubert
Copy link
Member

eteubert commented Dec 28, 2024

Wir sollten das Datum parsen, damit WordPress es auch garantiert versteht. Mein Ansatz war, mit dem timex package ein paar übliche Formate durchzuprobieren:

# mix.exs
{:timex, "~> 3.7"}
  defp wordpress_date(date) do
    date
    |> parse_date()
    |> DateTime.to_iso8601()
  end

  defp parse_date(date) do
    formats = [
      "{RFC822}",
      "{RFC822z}",
      "{RFC1123}",
      "{RFC1123z}",
      "{RFC3339}",
      "{RFC3339z}",
      "{ISO:Extended}",
      "{ISO:Extended:Z}"
    ]

    Enum.find_value(formats, fn format ->
      case Timex.parse(date, format) do
        {:ok, date} -> date
        {:error, _} -> false
      end
    end)
  end


payload = %{
content: content
content: content,
date: pub_date
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mit meinen Parser-Formatter-Funktionen:

Suggested change
date: pub_date
date: wordpress_date(pub_date)

@eteubert
Copy link
Member

#57

@eteubert eteubert merged commit 2880fd0 into main Dec 29, 2024
4 checks passed
@eteubert eteubert deleted the fix/issue_57 branch January 1, 2025 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants