linker_error
linker_error7mo ago

Date library

Can anyone recommend a decent working date library for deno? All the ones I'm trying (datefns, dayjs) are giving me errors or are not giving me types (no ctrl-click on symbols) in VS Code.
4 Replies
linker_error
linker_error7mo ago
Like, am I doing something wrong? This is crazy... every single package I try is either errors or no symbols...
"date_fns": "npm:date-fns@2.30.0",

"date_fns": "npm:date-fns@2.30.0",

I have this in my import map. My app compiles, but I don't get symbols. also tried importing both of these through esm.sh no dice
Deno AI Helper
Deno AI Helper7mo ago
I wasn't able to find a specific recommendation for a date library in the official Deno documentation. However, I can provide some general advice based on your message. If you're experiencing issues with libraries like date-fns or dayjs, it could be due to compatibility issues or incorrect imports. Since Deno uses ES modules, make sure you are importing the libraries correctly with the full path that includes the .ts or .js extension, and from a CDN that supports Deno if the library is not natively a Deno module. For instance, when using date-fns, you should import it from a Deno-compatible source like this:
import { format } from 'https://deno.land/x/date_fns/index.js';
import { format } from 'https://deno.land/x/date_fns/index.js';
For dayjs, you would need to find a version that is compatible with Deno or a CDN that provides it in a Deno-friendly format. Regarding the lack of types and the inability to use ctrl-click on symbols in VS Code, this could be due to missing type definitions for the libraries you are using. If the libraries are not natively built for Deno, they might not include type definitions that Deno or VS Code can automatically detect. You can sometimes find or create type definition files (.d.ts) for these libraries, which can help with type checking and editor features like symbol navigation. Please note that this advice is not based on the Deno documentation, and I would recommend double-checking the accuracy of this advice and looking for any updates or community solutions that might address these issues. Additionally, you might want to check the Deno third-party module registry (https://deno.land/x) for any date libraries that are specifically designed for Deno, as they are more likely to be compatible and come with proper type definitions.
jeff.hykin
jeff.hykin7mo ago
Yeah I didn't like the existing ones so I wrote my own
import DateTime from "https://deno.land/x/good@1.6.0.0/date.js"
import DateTime from "https://deno.land/x/good@1.6.0.0/date.js"
Note this is not a recommendation sadly, as it does not have any type annotations, it's very mutable, and it doesn't handle timezone all that well. Yet somehow it's still better than the built-in Date (it's backwards compatible with all methods)
jcayzac
jcayzac7mo ago
import moment from 'https://esm.sh/moment@2.29.4' seems to work fine for me There's also a https://deno.land/x/momentjs which claims to be a "Deno compatible" version, although I'm not sure what exactly is the problem with the vanilla/upstream version of Moment. Vanilla import from esm.sh works fine for me. That x/ library also seems abandonned (single commit 3 years ago).