refactor(deps): Replace moment with dayjs (#8192)

This commit is contained in:
Jonah Lawrence
2022-07-14 19:34:38 -06:00
committed by GitHub
parent 6a77a5991a
commit e8686395b1
10 changed files with 41 additions and 39 deletions

View File

@@ -2,8 +2,11 @@
* Commonly-used functions for formatting text in badge labels. Includes
* ordinal numbers, currency codes, star ratings, versions, etc.
*/
import moment from 'moment'
moment().format()
import dayjs from 'dayjs'
import calendar from 'dayjs/plugin/calendar.js'
import relativeTime from 'dayjs/plugin/relativeTime.js'
dayjs.extend(calendar)
dayjs.extend(relativeTime)
function starRating(rating, max = 5) {
const flooredRating = Math.floor(rating)
@@ -109,7 +112,7 @@ function maybePluralize(singular, countable, plural) {
}
function formatDate(d) {
const date = moment(d)
const date = dayjs(d)
const dateString = date.calendar(null, {
lastDay: '[yesterday]',
sameDay: '[today]',
@@ -117,12 +120,12 @@ function formatDate(d) {
sameElse: 'MMMM YYYY',
})
// Trim current year from date string
return dateString.replace(` ${moment().year()}`, '').toLowerCase()
return dateString.replace(` ${dayjs().year()}`, '').toLowerCase()
}
function formatRelativeDate(timestamp) {
return moment()
.to(moment.unix(parseInt(timestamp, 10)))
return dayjs()
.to(dayjs.unix(parseInt(timestamp, 10)))
.toLowerCase()
}