-
Notifications
You must be signed in to change notification settings - Fork 8
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
AP Date, but UTC #176
Comments
Hey @eyeseast! Just to make sure I'm following 100% can you elaborate further on what's happening? Maybe an example of the exact input, (incorrect) output you're seeing and output you'd expect/want? |
Hi! (Great library, btw.) Here's roughly what happens: const d = new Date('2020-05-05') // editor puts this in a spreadsheet
apdate(d)
// May 4, 2020, because timezones
d.toUTCString()
// "Tue, 05 May 2020 00:00:00 GMT" So what I'm proposing is a function alongside |
Thanks, that helps! This is tricky — The original version of We handle this by parsing any input ISO date strings with date-fns' const input = '2020-05-05';
// split and coerce to numbers
const [year, month, day] = input.split('-').map(Number);
// month is zero-indexed!
const d = new Date(year, month - 1, day); |
Here's more what I'm thinking, if this helps: export default function apdateUTC(date = new Date()) {
const month = apmonthUTC(date); // assume a UTC version for now
const dayOfMonth = date.getUTCDate();
const year = date.getUTCFullYear();
return `${month} ${dayOfMonth}, ${year}`;
} So it's the same function, but it gives you UTC instead of localized dates. (This is what I ended up doing in my own code.) I'm not worried about parsing at all here, just changing output. |
Sorry, I kind of rambled there! What I was getting at is this is happening because of a quirk of how passing a partial ISO-formatted date string into Instead of making a variation of |
Alright, we might have to disagree on this, which is totally fine. Happy to deal with this particular collision of javascript and editors on my end. Appreciate the feedback. |
Have run into this a couple times, and running into it now: Editor puts a localized datetime in a source doc. Javascript parses as UTC and displays in local time, which is offset. Now the date is off.
Simplest solution I can think of is to parse and display as UTC, probably as a separate function, alongside
apdate
.The text was updated successfully, but these errors were encountered: