picker icon indicating copy to clipboard operation
picker copied to clipboard

clone.weekday is not a function

Open ChiaJune opened this issue 4 years ago • 14 comments

dayjs <= 1.8.30 没有问题 dayjs > 1.8.30 点击日期选择器直接报错

TypeError: clone.weekday is not a function
    in DateBody (created by DatePanel)
    in div (created by DatePanel)
    in DatePanel (created by PickerPanel)
    in div (created by PickerPanel)
    in PickerPanel (created by InnerPicker)
    in div (created by InnerPicker)
    in div (created by PopupInner)
    in PopupInner (created by Align)
    in Align (created by CSSMotion)
    in CSSMotion (created by ForwardRef)
    in ForwardRef (created by Popup)
    in div (created by Popup)
    in Popup (created by Trigger)
    in Portal (created by Trigger)
    in Trigger (created by PickerTrigger)
    in PickerTrigger (created by InnerPicker)
    in InnerPicker (created by Picker)
    in Picker (created by Context.Consumer)
    in LocaleReceiver (created by Picker)
    in Picker (at Header.tsx:35)
    in header (at Header.tsx:33)
    in div (at Header.tsx:32)

ChiaJune avatar Aug 10 '20 08:08 ChiaJune

Same here.

oferitz avatar Aug 13 '20 05:08 oferitz

This is still an issue. Please lock dayjs version to 1.8.30

oferitz avatar Sep 21 '20 09:09 oferitz

This workaround solves the issue without having to downgrade dayjs:

https://github.com/ant-design/ant-design/issues/26190#issuecomment-703673400

Those lines should be added into this library.

marian2js avatar Oct 20 '20 20:10 marian2js

I want to be able to use dayjs v1.9.x because they've fixed a slew of timezone-related issues from 1.8.3x, but it appears this library makes it impossible to use v1.9.x for now.

jstaro avatar Oct 21 '20 15:10 jstaro

@jstaro check my previous comment, you can use the latest dayjs by adding these lines. It worked for me with dayjs 1.9.3.

marian2js avatar Oct 21 '20 16:10 marian2js

@marian2js Yes I tried doing that, but it doesn't seem to work with the latest version of AntD (which relies on rc-picker) and the way antd-dayjs-webpack-plugin loads dayjs, it seems.

jstaro avatar Oct 21 '20 17:10 jstaro

@jstaro found a way to do this.

import dayjs from 'dayjs'
import advancedFormat from 'dayjs/plugin/advancedFormat'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import localeData from 'dayjs/plugin/localeData'
import weekday from 'dayjs/plugin/weekday'
import weekOfYear from 'dayjs/plugin/weekOfYear'
import weekYear from 'dayjs/plugin/weekYear'

dayjs.extend(customParseFormat)
dayjs.extend(advancedFormat)
dayjs.extend(weekday)
dayjs.extend(localeData)
dayjs.extend(weekOfYear)
dayjs.extend(weekYear)

iMuFeng avatar Nov 17 '20 08:11 iMuFeng

@iMuFeng Thank you for the workaround. I will keep that in mind if we need it again! For now, we migrated our user code to use Luxon and only treat dayjs as a follow-along dependency of AntDesign, since we cannot fully control the version used.

jstaro avatar Nov 23 '20 07:11 jstaro

Any update?

Jay-flow avatar Dec 13 '22 06:12 Jay-flow

same error

smithyj avatar Jan 06 '23 10:01 smithyj

@jstaro found a way to do this.

import dayjs from 'dayjs'
import advancedFormat from 'dayjs/plugin/advancedFormat'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import localeData from 'dayjs/plugin/localeData'
import weekday from 'dayjs/plugin/weekday'
import weekOfYear from 'dayjs/plugin/weekOfYear'
import weekYear from 'dayjs/plugin/weekYear'

dayjs.extend(customParseFormat)
dayjs.extend(advancedFormat)
dayjs.extend(weekday)
dayjs.extend(localeData)
dayjs.extend(weekOfYear)
dayjs.extend(weekYear)

it's work

smithyj avatar Jan 06 '23 10:01 smithyj

dayjs => 1.11.9

在没有使用导入dayjs自带国际化配置时候是正常的 导入后就出现了 。 使用上面 @iMuFeng 这个办法可以愉快工作。 我只是一个菜鸟程序员,从这段修补代码方式上我感觉是导出的dayjs覆盖了原有的DatePicker中的dayjs。

"It was working fine without importing the built-in internationalization configuration of dayjs, but after importing it, the issue occurred. Using the method mentioned above seems to work well. I'm just a novice programmer, but based on this code patch, it seems that the imported dayjs is overriding the original dayjs used in the DatePicker."

UnforgetMemory avatar Aug 07 '23 09:08 UnforgetMemory

@jstaro found a way to do this.

import dayjs from 'dayjs'
import advancedFormat from 'dayjs/plugin/advancedFormat'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import localeData from 'dayjs/plugin/localeData'
import weekday from 'dayjs/plugin/weekday'
import weekOfYear from 'dayjs/plugin/weekOfYear'
import weekYear from 'dayjs/plugin/weekYear'

dayjs.extend(customParseFormat)
dayjs.extend(advancedFormat)
dayjs.extend(weekday)
dayjs.extend(localeData)
dayjs.extend(weekOfYear)
dayjs.extend(weekYear)

thank you, it's work

OlyLis1005 avatar Oct 08 '23 06:10 OlyLis1005

I wonder why this is still the issue 😳, there is lack of information inside the official docs 😞

I created adapter based only your solution, so it's more elegant to import inside components:

// this is adapter for antd datepicker
// import it instead of the original dayjs
// more info here: https://github.com/react-component/picker/issues/123#issuecomment-728755491

import dj from 'dayjs'
import advancedFormat from 'dayjs/plugin/advancedFormat'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import localeData from 'dayjs/plugin/localeData'
import weekday from 'dayjs/plugin/weekday'
import weekOfYear from 'dayjs/plugin/weekOfYear'
import weekYear from 'dayjs/plugin/weekYear'

dj.extend(customParseFormat)
dj.extend(advancedFormat)
dj.extend(weekday)
dj.extend(localeData)
dj.extend(weekOfYear)
dj.extend(weekYear)

export const dayjs = dj;

pavelee avatar Jun 07 '24 17:06 pavelee