diff --git a/frontend/model/contracts/group.js b/frontend/model/contracts/group.js index 1d3ed9718d..1c08b834ce 100644 --- a/frontend/model/contracts/group.js +++ b/frontend/model/contracts/group.js @@ -14,7 +14,7 @@ import { import { paymentStatusType, paymentType, PAYMENT_COMPLETED } from './shared/payments/index.js' import { createPaymentInfo, paymentHashesFromPaymentPeriod } from './shared/functions.js' import { merge, deepEqualJSONType, omit, cloneDeep } from './shared/giLodash.js' -import { addTimeToDate, dateToPeriodStamp, compareISOTimestamps, dateFromPeriodStamp, isPeriodStamp, comparePeriodStamps, dateIsWithinPeriod, DAYS_MILLIS } from './shared/time.js' +import { addTimeToDate, dateToPeriodStamp, compareISOTimestamps, dateFromPeriodStamp, isIsoString, isPeriodStamp, comparePeriodStamps, dateIsWithinPeriod, DAYS_MILLIS } from './shared/time.js' import { unadjustedDistribution, adjustedDistribution } from './shared/distribution/distribution.js' import currencies from './shared/currencies.js' import { inviteType, chatRoomAttributesType } from './shared/types.js' @@ -324,7 +324,7 @@ sbp('chelonia/defineContract', { periodStampGivenDate (state, getters) { return (recentDate: string | Date) => { if (typeof recentDate !== 'string') recentDate = recentDate.toISOString() - if (!isPeriodStamp(recentDate)) throw new TypeError('must be date or isostring') + if (!isIsoString(recentDate)) throw new TypeError('must be date or isostring') const { distributionDate, distributionPeriodLength } = getters.groupSettings if (!distributionDate) return const sortedPeriodKeys = getters.groupSortedPeriodKeys @@ -349,7 +349,7 @@ sbp('chelonia/defineContract', { const waitingPeriodStamp = dateToPeriodStamp( addTimeToDate(distributionDate, -distributionPeriodLength) ) - return recentDate >= waitingPeriodStamp ? waitingPeriodStamp : undefined + return recentDate >= dateFromPeriodStamp(waitingPeriodStamp) ? waitingPeriodStamp : undefined } const oldestKnownStamp = sortedPeriodKeys[0] const latestKnownStamp = sortedPeriodKeys[sortedPeriodKeys.length - 1] @@ -375,7 +375,7 @@ sbp('chelonia/defineContract', { if (!distributionDate) return // This is not always the current period stamp. const distributionDateStamp = dateToPeriodStamp(distributionDate) - const sortedPeriodKeys = getters.groupSortedPeriodKeys + const sortedPeriodKeys = getters.groupSortedPeriodKseys const latestKnownStamp = sortedPeriodKeys[sortedPeriodKeys.length - 1] // Maybe the distribution date has just been updated, // but the corresponding period has not started or is not stored yet. diff --git a/frontend/model/contracts/manifests.json b/frontend/model/contracts/manifests.json index f833852102..4ea9eec712 100644 --- a/frontend/model/contracts/manifests.json +++ b/frontend/model/contracts/manifests.json @@ -1,7 +1,7 @@ { "manifests": { "gi.contracts/chatroom": "21XWnNS9zeT2tws6KkJqkibLGfTivPdiGYbSjjqFEkDjL5Q775", - "gi.contracts/group": "21XWnNK3pmNAdgXLe7rkjVjEQ1z3Lccp3o7YpZ64bAr18VNPAW", + "gi.contracts/group": "21XWnNPBQsrLKSPxFX8kT5g2E9pym4q2gvnzfXp2T8zHfaNqKp", "gi.contracts/identity": "21XWnNN7wGNxzFZmiS4ft2TumavYYAgemSuFrGavTVJpxqtnyg", "gi.contracts/mailbox": "21XWnNHJ7MALCinR7vnu4GM82nq5DLhe6nhEDzruTuTw9CTnXP" } diff --git a/frontend/model/contracts/shared/time.js b/frontend/model/contracts/shared/time.js index 23484f201e..a5384dddc8 100644 --- a/frontend/model/contracts/shared/time.js +++ b/frontend/model/contracts/shared/time.js @@ -132,13 +132,17 @@ export function humanDate ( } export function isPeriodStamp (arg: string): boolean { - return /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(arg) + return isIsoString(arg) } export function isFullMonthstamp (arg: string): boolean { return /^\d{4}-(0[1-9]|1[0-2])$/.test(arg) } +export function isIsoString (arg: string): boolean { + return typeof arg === 'string' && /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(arg) +} + export function isMonthstamp (arg: string): boolean { return isShortMonthstamp(arg) || isFullMonthstamp(arg) }