-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Dayjs: r.ordinal is not a function at advanceFormat.js #1891
Comments
@iamkun ^^ |
|
That's correct as when we remove |
I didn't try the code in Chrome, but only on my node.js system.
should be Perhaps this was the culprit - otherwise I will have to test it on chrome ;-) |
@BePo65 In actual implementation I used |
So I will have to test it on Chrome - will be back soon 😄 |
@BePo65 In your implementation, it seems to work fine but I used it in React application, not sure if that affects the working. But I still see that error. |
HM, perhaps a type definition thing. Do you have a small demo e.g. in CodeSandbox or something like this? |
Same problem |
Can anybody try to fork and modify this demo to reproduce the issue? I can't reproduce this too. |
Perhaps @Kashish-Chaudhary could create a demo of the problem in a sandbox react playground? I tested it with plain typescript (in my repo dayjs-typescript-demo calling |
@BePo65 FYI, here is a code to reproduce the issue. You can reproduce this when you change the locale globally. It also happens only if you set 'en' as the locale. I tried using 'nn', 'nb', 'de' locales and the code work fine for those but not for 'en'. <!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>dayjs issue 1891</title>
</head>
<body>
<h1 id="header">dayjs issue 1891</h1>
<p id="result">waiting...</p>
<script src="https://unpkg.com/dayjs@1.11.3/dayjs.min.js"></script>
<script src="https://unpkg.com/dayjs@1.11.3/plugin/advancedFormat.js"></script>
<script src="https://unpkg.com/dayjs@1.11.3/locale/en"></script>
<script>
var customLocale = window.dayjs_locale_en; // this happens only when 'en' is used as the locale
dayjs.locale({...customLocale})
dayjs.extend(window.dayjs_plugin_advancedFormat)
const endDate = '2022-12-31'
const formattedDate = dayjs(endDate).format("MMMM Do, YYYY");
document.getElementById("result").innerHTML = formattedDate;
console.log(formattedDate)
</script>
</body>
</html> |
I can reproduce the effect with your code. The problem is the way you activate the locale. But anyway this is not the recommended way to activate a locale. IMHO the code should look like this (works on my system):
Perhaps this helps you solve your issue :-) |
|
I checked all locale files in the dev branch of dayjs and all contain a 'ordinal' function besides 'en' that gets a 'ordinal' function by the 'AdvancedFormat' plugin. Did I miss a locale? IMHO the 'ordinal' function of 'en' should be part of the core dayjs file and not of the 'AdvancedFormat' plugin. |
Describe the bug
When I try to format the date to show ordinal for date it breaks the app and shows error r.ordinal is not a function.
Code:
import dayjs from 'dayjs';
import advancedFormat from 'dayjs/plugin/advancedFormat';
dayjs.extend(advancedFormat);
const formattedDate = dayjs(endDate).format("MMMM Do, YYYY");
Expected behavior
It should format date in this format => December 31st, 2022
Information
The text was updated successfully, but these errors were encountered: