qmd-lab / scheduled-docs

A Quarto Extension to schedule the publication of documents in websites and blogs.
MIT License
5 stars 1 forks source link

Allow reasonable date formats #5

Open srvanderplas opened 2 months ago

srvanderplas commented 2 months ago

Currently, scheduled-docs requires m/d/y format (or d/m/y format, I'm not sure). Allow for locale-specific date formats as well as ISO standard yyyy-mm-dd formats.

andrewpbray commented 2 months ago

Thanks for the issue!

I'm handling the dates in Typsescript with the interpreter that ships with Quarto called Deno. I was very sad to learn that Deno does not include the libraries that resolve locales timezones into specific UTC offsets (which is a bummer because that's a great way to specify them!).

I'll keep this issue open to revisit when I have a moment to take another dive into the different ways this can be done to be sure I've exhausted the possibilities.

paciorek commented 2 weeks ago

@andrewpbray I'm confused about the difficulty here. I would think that what needs to be done is to modify convertDateToISOFormat to be more flexible in terms of input format but continue to return the ISO standard as the output.

It would try to determine the input format. Minimally this could distinguish {M,}M/{D,}D/YY from ISO YYYY-MM-DD. If the latter, it would return${dateStr}T00:00:00${timezone};, since the date part is already ISO standard.

andrewpbray commented 2 weeks ago

Yes, you're totally right on the date formatting part. My comment was about locale approach so that it could do the right thing in terms of the offset during daylight savings times for locales that observe it.

It's possible that we can also take advantage of the datetime library to do this processing without having to handwrite this stuff. I came across this the other day:

https://prerelease.quarto.org/docs/projects/scripts.html#deno-scripts

(Actually, i came upon this because I updated my local installation to the most recent version of Quarto and this change is the 1 breaking change to v1.6 and it breaks scheduled-docs. I'll update this repo once 1.6 is released.)

paciorek commented 1 week ago

Here's a proposal for the date formatting stuff:

  1. Default to assuming ISO yyyy-MM-dd format for more generality.
  2. Allow the user to provide a date string format in config.yml (e.g., MM/dd/yyyy) that is parsed via parse from "https://deno.land/std@0.224.0/datetime/parse.ts".
    • E.g., parse("20-01-2019", "MM/dd/yyyy")).
    • Would need to check if parse can handle MM/dd/yy.

@andrewpbray I'm happy to work on a PR if this seems like a good path forward.

andrewpbray commented 1 week ago

That'd be great - PR welcomed!

paciorek commented 1 week ago

This is in PR #14