Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace moment with dayjs [github node sourceforge wordpress aur eclipse steam vaadin visualstudio] #8192

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions services/color-formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module
*/

import moment from 'moment'
import dayjs from 'dayjs'
import pep440 from '@renovate/pep440'

/**
Expand Down Expand Up @@ -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)
}

Expand Down
9 changes: 3 additions & 6 deletions services/github/github-hacktoberfest.service.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }
}
Expand Down
4 changes: 2 additions & 2 deletions services/github/github-release-date.service.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions services/node/node-version-color.js
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions services/node/testUtils/test-utils.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -67,7 +67,7 @@ const mockVersionsSha = () => nock => {
}

const mockReleaseSchedule = () => nock => {
const currentDate = moment()
const currentDate = dayjs()
const schedule = {
'v0.10': {
start: '2013-03-11',
Expand Down
10 changes: 5 additions & 5 deletions services/sourceforge/sourceforge.service.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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),
},
}

Expand Down Expand Up @@ -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: {
Expand Down
15 changes: 9 additions & 6 deletions services/text-formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -109,20 +112,20 @@ 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]',
lastWeek: '[last] dddd',
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()
}

Expand Down
8 changes: 5 additions & 3 deletions services/wordpress/wordpress-last-update.service.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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')
Expand Down