diff --git a/package-lock.json b/package-lock.json index 9f9701d8d2f32..f7170ca2aef42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "cloudflare-middleware": "^1.0.4", "config": "^3.3.7", "cross-env": "^7.0.3", + "dayjs": "^1.11.3", "decamelize": "^3.2.0", "emojic": "^1.1.17", "escape-string-regexp": "^4.0.0", @@ -39,7 +40,6 @@ "lodash.countby": "^4.6.0", "lodash.groupby": "^4.6.0", "lodash.times": "^4.3.2", - "moment": "^2.29.4", "node-env-flag": "^0.1.0", "parse-link-header": "^2.0.0", "path-to-regexp": "^6.2.1", @@ -9325,10 +9325,9 @@ } }, "node_modules/dayjs": { - "version": "1.10.4", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.4.tgz", - "integrity": "sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw==", - "dev": true + "version": "1.11.3", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.3.tgz", + "integrity": "sha512-xxwlswWOlGhzgQ4TKzASQkUhqERI3egRNqgV4ScR8wlANA/A9tZ7miXa44vTTKEq5l7vWoL5G57bG3zA+Kow0A==" }, "node_modules/debug": { "version": "2.6.9", @@ -20842,6 +20841,7 @@ "version": "2.29.4", "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", + "dev": true, "engines": { "node": "*" } @@ -37732,10 +37732,9 @@ "dev": true }, "dayjs": { - "version": "1.10.4", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.4.tgz", - "integrity": "sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw==", - "dev": true + "version": "1.11.3", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.3.tgz", + "integrity": "sha512-xxwlswWOlGhzgQ4TKzASQkUhqERI3egRNqgV4ScR8wlANA/A9tZ7miXa44vTTKEq5l7vWoL5G57bG3zA+Kow0A==" }, "debug": { "version": "2.6.9", @@ -46540,7 +46539,8 @@ "moment": { "version": "2.29.4", "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", - "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==" + "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", + "dev": true }, "ms": { "version": "2.0.0", diff --git a/package.json b/package.json index 262a385c8ec8d..e776a52a2fe03 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "cloudflare-middleware": "^1.0.4", "config": "^3.3.7", "cross-env": "^7.0.3", + "dayjs": "^1.11.3", "decamelize": "^3.2.0", "emojic": "^1.1.17", "escape-string-regexp": "^4.0.0", @@ -51,7 +52,6 @@ "lodash.countby": "^4.6.0", "lodash.groupby": "^4.6.0", "lodash.times": "^4.3.2", - "moment": "^2.29.4", "node-env-flag": "^0.1.0", "parse-link-header": "^2.0.0", "path-to-regexp": "^6.2.1", diff --git a/services/color-formatters.js b/services/color-formatters.js index 518a2a51f5954..5cf6da7c712be 100644 --- a/services/color-formatters.js +++ b/services/color-formatters.js @@ -5,7 +5,7 @@ * @module */ -import moment from 'moment' +import dayjs from 'dayjs' import pep440 from '@renovate/pep440' /** @@ -182,7 +182,7 @@ function colorScale(steps, colors, reversed) { */ function age(date) { const colorByAge = colorScale([7, 30, 180, 365, 730], undefined, true) - const daysElapsed = moment().diff(moment(date), 'days') + const daysElapsed = dayjs().diff(dayjs(date), 'days') return colorByAge(daysElapsed) } diff --git a/services/github/github-hacktoberfest.service.js b/services/github/github-hacktoberfest.service.js index c78311f896318..46299fb1c5972 100644 --- a/services/github/github-hacktoberfest.service.js +++ b/services/github/github-hacktoberfest.service.js @@ -1,6 +1,6 @@ import gql from 'graphql-tag' import Joi from 'joi' -import moment from 'moment' +import dayjs from 'dayjs' import { metric, maybePluralize } from '../text-formatters.js' import { nonNegativeInteger } from '../validators.js' import { GithubAuthV4Service } from './github-auth-service.js' @@ -121,7 +121,7 @@ export default class GithubHacktoberfestCombinedStatus extends GithubAuthV4Servi // The global cutoff time is 11/1 noon UTC. // https://github.com/badges/shields/pull/4109#discussion_r330782093 // We want to show "1 day left" on the last day so we add 1. - daysLeft = moment(`${year}-11-01 12:00:00 Z`).diff(moment(), 'days') + 1 + daysLeft = dayjs(`${year}-11-01 12:00:00 Z`).diff(dayjs(), 'days') + 1 } if (daysLeft < 0) { return { @@ -205,10 +205,7 @@ export default class GithubHacktoberfestCombinedStatus extends GithubAuthV4Servi } static getCalendarPosition(year) { - const daysToStart = moment(`${year}-10-01 00:00:00 Z`).diff( - moment(), - 'days' - ) + const daysToStart = dayjs(`${year}-10-01 00:00:00 Z`).diff(dayjs(), 'days') const isBefore = daysToStart > 0 return { daysToStart, isBefore } } diff --git a/services/github/github-release-date.service.js b/services/github/github-release-date.service.js index 098bb7c11cc84..c90c44cf10217 100644 --- a/services/github/github-release-date.service.js +++ b/services/github/github-release-date.service.js @@ -1,4 +1,4 @@ -import moment from 'moment' +import dayjs from 'dayjs' import Joi from 'joi' import { age } from '../color-formatters.js' import { formatDate } from '../text-formatters.js' @@ -51,7 +51,7 @@ export default class GithubReleaseDate extends GithubAuthV3Service { static defaultBadgeData = { label: 'release date' } static render({ date }) { - const releaseDate = moment(date) + const releaseDate = dayjs(date) return { message: formatDate(releaseDate), color: age(releaseDate), diff --git a/services/node/node-version-color.js b/services/node/node-version-color.js index 9d36a36f849cc..675c9f00b947c 100644 --- a/services/node/node-version-color.js +++ b/services/node/node-version-color.js @@ -1,4 +1,4 @@ -import moment from 'moment' +import dayjs from 'dayjs' import semver from 'semver' import { getCachedResource } from '../../core/base-service/resource-cache.js' @@ -23,7 +23,7 @@ async function getVersion(version) { } function ltsVersionsScraper(versions) { - const currentDate = moment().format(dateFormat) + const currentDate = dayjs().format(dateFormat) return Object.keys(versions).filter(function (version) { const data = versions[version] return data.lts && data.lts < currentDate && data.end > currentDate diff --git a/services/node/testUtils/test-utils.js b/services/node/testUtils/test-utils.js index 2a7535ce04cf4..4a3b7c4b4324c 100644 --- a/services/node/testUtils/test-utils.js +++ b/services/node/testUtils/test-utils.js @@ -1,7 +1,7 @@ import fs from 'fs' import path from 'path' import { fileURLToPath } from 'url' -import moment from 'moment' +import dayjs from 'dayjs' const dateFormat = 'YYYY-MM-DD' @@ -67,7 +67,7 @@ const mockVersionsSha = () => nock => { } const mockReleaseSchedule = () => nock => { - const currentDate = moment() + const currentDate = dayjs() const schedule = { 'v0.10': { start: '2013-03-11', diff --git a/services/sourceforge/sourceforge.service.js b/services/sourceforge/sourceforge.service.js index a6feca914ca54..ebbe1e46e595c 100644 --- a/services/sourceforge/sourceforge.service.js +++ b/services/sourceforge/sourceforge.service.js @@ -1,5 +1,5 @@ import Joi from 'joi' -import moment from 'moment' +import dayjs from 'dayjs' import { renderDownloadsBadge } from '../downloads.js' import { nonNegativeInteger } from '../validators.js' import { BaseJsonService } from '../index.js' @@ -15,15 +15,15 @@ const intervalMap = { }, dw: { // 6 days, since date range is inclusive, - startDate: endDate => moment(endDate).subtract(6, 'days'), + startDate: endDate => dayjs(endDate).subtract(6, 'days'), interval: 'week', }, dm: { - startDate: endDate => moment(endDate).subtract(30, 'days'), + startDate: endDate => dayjs(endDate).subtract(30, 'days'), interval: 'month', }, dt: { - startDate: () => moment(0), + startDate: () => dayjs(0), }, } @@ -78,7 +78,7 @@ export default class Sourceforge extends BaseJsonService { folder ? `${folder}/` : '' }stats/json` // get yesterday since today is incomplete - const endDate = moment().subtract(24, 'hours') + const endDate = dayjs().subtract(24, 'hours') const startDate = intervalMap[interval].startDate(endDate) const options = { searchParams: { diff --git a/services/text-formatters.js b/services/text-formatters.js index 7470642180123..519ddc13ac405 100644 --- a/services/text-formatters.js +++ b/services/text-formatters.js @@ -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() } diff --git a/services/wordpress/wordpress-last-update.service.js b/services/wordpress/wordpress-last-update.service.js index eb7ae157bb142..a714ed9a90d82 100644 --- a/services/wordpress/wordpress-last-update.service.js +++ b/services/wordpress/wordpress-last-update.service.js @@ -1,14 +1,16 @@ -import moment from 'moment' +import dayjs from 'dayjs' +import customParseFormat from 'dayjs/plugin/customParseFormat.js' import { InvalidResponse } from '../index.js' import { formatDate } from '../text-formatters.js' import { age as ageColor } from '../color-formatters.js' import { documentation, BaseWordpress } from './wordpress-base.js' +dayjs.extend(customParseFormat) const extensionData = { plugin: { capt: 'Plugin', exampleSlug: 'bbpress', - lastUpdateFormat: 'YYYY-MM-DD hh:mma GMT', + lastUpdateFormat: 'YYYY-MM-DD hh:mma [GMT]', }, theme: { capt: 'Theme', @@ -50,7 +52,7 @@ function LastUpdateForType(extensionType) { } transform(lastUpdate) { - const date = moment(lastUpdate, lastUpdateFormat) + const date = dayjs(lastUpdate, lastUpdateFormat) if (date.isValid()) { return date.format('YYYY-MM-DD')