question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calendar format returns wrong date

See original GitHub issue

Hello!

I have the following snippet:

import calendar from 'dayjs/plugin/calendar';
dayjs.extend(calendar);

return dayjs().calendar(dayjs(date), {
        sameDay: '[Today]',
        nextDay: '[Tomorrow]',
        nextWeek: 'dddd',
        lastDay: '[Yesterday]',
        lastWeek: '[Last] dddd',
        sameElse: 'DD/MM/YYYY',
 });

The problems , in my opinion, are :

  • if the date falls under the sameElse category i get the date of today ( since today is 16/11/2020, i get 16/11/2020 for all dates that fall under sameElse)
  • all dates under next and last are inverted - meaning if i choose 17/11/2020, i get yesterday, and i if choose 15/11/2020, i get tomorrow
  • also, for dates such as 18/11/2020,19/11/2020 i get last Monday instead of Wednesday or Thursday, and for dates such as 14/11/2020 i get Monday instead of last Sunday

If I’m missing something from the documentation, please let me know, but in my opinion this isn’t the right behaviour for this function.

Thank you for your time!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

18reactions
TeChn4Kcommented, Apr 21, 2021

I solved this issue by switching the two dates :

// wrong
dayjs().calendar(dayjs(date))

// good
dayjs(date).calendar(dayjs())

// better!
dayjs(date).calendar()

I don’t know if the issue is about the documentation or the calendar plugin.

3reactions
leslie-heinzencommented, Mar 5, 2021

Any update on this? I’m patching the plugin for now similar to what @borie88 helpfully suggested above. Just curious if this will make it into the library.

Here’s a reproduction if anyone else encountering this issue wants to look: https://codesandbox.io/s/billowing-dream-7obed

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Calendar returns wrong date
MONTH) throws an exception, when the month isn't the same. My start date is 1/12/2017 and enddate is 31/12/2017. so the month should...
Read more >
Date in Swift printed is wrong
This is because the date is stored in Swift as UTC time, i.e. as at longitude 0.0 - which used to be called...
Read more >
Moment.js | Docs
If the string or format you are asking to change is reflected in the CLDR, ... is not able to be parsed with...
Read more >
Format Function
Returns a Variant (String) containing an expression formatted according to ... If the calendar is Hijri, all date format symbols (for example, dddd,...
Read more >
System.date.format() returns wrong calendar week - Ignition
Hi there, i am calculating the calendar week from a timestamp in a property transform script. The script is not returning what I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found