diff --git a/ghost/limit-service/lib/date-utils.js b/ghost/limit-service/lib/date-utils.js index f27da80eb7..7e1943137b 100644 --- a/ghost/limit-service/lib/date-utils.js +++ b/ghost/limit-service/lib/date-utils.js @@ -1,6 +1,4 @@ -const differenceInMonths = require('date-fns/differenceInMonths'); -const parseISO = require('date-fns/parseISO'); -const addMonths = require('date-fns/addMonths'); +const {DateTime} = require('luxon'); const SUPPORTED_INTERVALS = ['month']; /** @@ -14,11 +12,13 @@ const SUPPORTED_INTERVALS = ['month']; */ const lastPeriodStart = (startDate, interval) => { if (interval === 'month') { - const startDateISO = parseISO(startDate); - const fullPeriodsPast = differenceInMonths(new Date(), startDateISO); - const lastPeriodStartDate = addMonths(startDateISO, fullPeriodsPast); + const startDateISO = DateTime.fromISO(startDate, {zone: 'UTC'}); + const now = DateTime.now().setZone('UTC'); + const fullPeriodsPast = Math.floor(now.diff(startDateISO, 'months').months); - return lastPeriodStartDate.toISOString(); + const lastPeriodStartDate = startDateISO.plus({months: fullPeriodsPast}); + + return lastPeriodStartDate.toISO(); } throw new Error('Invalid interval specified. Only "month" value is accepted.'); diff --git a/ghost/limit-service/package.json b/ghost/limit-service/package.json index 7adf0681cb..76130d0df3 100644 --- a/ghost/limit-service/package.json +++ b/ghost/limit-service/package.json @@ -26,6 +26,7 @@ "sinon": "10.0.0" }, "dependencies": { - "lodash": "^4.17.21" + "lodash": "^4.17.21", + "luxon": "^1.26.0" } }