You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Parsing a date with customParseFormat, then using utcOffset with keepLocaltime breaks diff
Running this snippet demonstrates the issue:
importdayjsfrom"https://cdn.skypack.dev/dayjs@1.10.5";importutcfrom"https://cdn.skypack.dev/dayjs@1.10.5/plugin/utc";importcustomParseFormatfrom"https://cdn.skypack.dev/dayjs@1.10.5/plugin/customParseFormat";dayjs.extend(customParseFormat);dayjs.extend(utc);constdateTime=dayjs('2021-06-18','YYYY-MM-DD').utcOffset(-240,true);// No $xconstnow=dayjs().utcOffset(-240);constdiff=dateTime.diff(now,'days');console.log('diff:',diff);// breaks
Uncaught TypeError: Cannot read property '$localOffset' of undefined
at M2.u.valueOf (utc.js:63)
at M2.m2.diff (dayjs.js:180)
at M2.u.diff (utc.js:79)
Expected behavior diff works as expected
I'm using this (really ugly) workaround in the meantime
;(dayasany).$x={}
Information
Day.js Version v1.10.5
OS: Windows
Browser: Edge 91.0.864.48
Time zone: UTC-04:00 PYT
The text was updated successfully, but these errors were encountered:
importdayjs,{ConfigType,OpUnitType,QUnitType}from'dayjs'importcustomParseFormatfrom'dayjs/plugin/customParseFormat'importutcfrom'dayjs/plugin/utc'dayjs.extend(customParseFormat)dayjs.extend(utc)// Work around dayjs bugdayjs.extend(function(_,Dayjs,__){constoldDiff=Dayjs.prototype.diffDayjs.prototype.diff=function(date: ConfigType,unit?: QUnitType|OpUnitType,float?: boolean): number{typeT=dayjs.Dayjs&{$x: {}|undefined}constself=thisasTconstother=dateasTself.$x??={}other.$x??={}returnoldDiff.call(self,date,unit,float)}})
Describe the bug
Parsing a date with
customParseFormat
, then usingutcOffset
withkeepLocaltime
breaksdiff
Running this snippet demonstrates the issue:
Expected behavior
diff
works as expectedI'm using this (really ugly) workaround in the meantime
Information
The text was updated successfully, but these errors were encountered: