dayjs / dayjs-website

⏰Day.js website repo
http://day.js.org/
MIT License
65 stars 228 forks source link

Fix incorrect documentation on calendar.md #19

Closed mglavall closed 4 years ago

mglavall commented 4 years ago

dddd, [Yesterday], and '[Last] dddd' doesn't show the time. Another possible fix would be to add the time to the format.

iamkun commented 4 years ago
var dayjs = require("dayjs")
var calendar = require('dayjs/plugin/calendar')
dayjs.extend(calendar)

dayjs().add(-1,'day').calendar()

result "Yesterday at 10:17 PM", so this should be correct

mglavall commented 4 years ago
var dayjs = require("dayjs")
var calendar = require('dayjs/plugin/calendar')
dayjs.extend(calendar)

dayjs().add(-1,'day').calendar()

result "Yesterday at 10:17 PM", so this should be correct

Because you aren't using the custom option, that's what I'm changing in the PR, try this:

var dayjs = require("dayjs")
var calendar = require('dayjs/plugin/calendar')
dayjs.extend(calendar)

dayjs().add(-1,'day').calendar(null, {
  sameDay: '[Today at] h:mm A', // The same day ( Today at 2:30 AM )
  nextDay: '[Tomorrow]', // The next day ( Tomorrow at 2:30 AM )
  nextWeek: 'dddd', // The next week ( Sunday )
  lastDay: '[Yesterday]', // The day before ( Yesterday ) 
  lastWeek: '[Last] dddd', // Last week ( Last Monday )
  sameElse: 'DD/MM/YYYY' // Everything else ( 7/10/2011 )
})
iamkun commented 4 years ago

Oh, I see! Thanks.

Maybe updating the custom string instead of the comment will be better? https://github.com/iamkun/dayjs/blob/dev/src/plugin/calendar/index.js#L4

like

lastDay: [Yesterday at] h:mm A // The day before ( Yesterday at 2:30 AM )
mglavall commented 4 years ago

Yes, I think that's good as well. Done :)

iamkun commented 4 years ago

looks great, thanks