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
Is there a way to get both FP and UTC functionality? #3755
Comments
I found this (old?) documentation which mentioned UTC being in development, and included instructions for how to import the package to use either FP, UTC, or both:
But that seems like outdated information at this point, as the latest docs no longer mention UTC in that section. After installing the latest
Was support for this removed? |
These old docs are no good. I think at some point in v2 there were undocumented UTC variations for some date-fns functions, but since v3 the way to go is to use the UTCDate package you originally mentioned. So, it should work - with some caveats though:
Building off the example in the docs for FP use: import { UTCDate } from '@date-fns/utc';
import { addYears, format } from 'date-fns/fp';
import { flow } from 'lodash-es';
const addFiveYears = addYears(5);
const formatToString = format('yyyy-MM-dd');
const dates = [new UTCDate(2017, 0, 1), new UTCDate(2017, 1, 11), new UTCDate(2017, 6, 2)];
const results = dates.map(flow(addFiveYears, formatToString));
console.log(results); // [ '2022-01-01', '2022-02-11', '2022-07-02' ] |
I expected that to return |
You need to use UTCDate along with date-fns v3 for things to work properly (sorry if I wasn't clear). Looking at your logs I'm pretty sure it's v2 and the I double checked and it does work for me with v3. import { UTCDate } from '@date-fns/utc';
import { startOfDay } from 'date-fns/fp';
const date = new UTCDate('2024-03-29');
console.log(date); // UTCDate 2024-03-29T00:00:00.000Z
console.log(startOfDay(date)); // UTCDate 2024-03-29T00:00:00.000Z |
Thanks for the clarification! After updating the |
I see that there is a date-fns/fp submodule and a date-fns/utc package, but is there a way to combine them?
The text was updated successfully, but these errors were encountered: