Skip to content

Commit

Permalink
fix: date wrangling
Browse files Browse the repository at this point in the history
  • Loading branch information
thorkellmani committed Oct 31, 2024
1 parent f615295 commit b679c76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class MachineLicenseClient
): LicensePkPassAvailability {
const expirationDate = licenseInfo
? findLatestExpirationDate(licenseInfo)
: undefined
: null

if (!licenseInfo || !expirationDate) {
return LicensePkPassAvailability.Unknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ import is from 'date-fns/locale/is'
import enGB from 'date-fns/locale/en-GB'
import { format as formatSsn } from 'kennitala'

const compareDates = (newDate: Date, latestDate?: Date) =>
!latestDate || newDate > latestDate ? newDate : latestDate

export const findLatestExpirationDate = (license: VinnuvelaDto) => {
if (!license.vinnuvelaRettindi) {
return null
}

let maxDate = new Date()
let latestDate: Date | undefined
for (const right of license.vinnuvelaRettindi) {
if (right.stjorna && new Date(right.stjorna) > maxDate) {
maxDate = new Date(right.stjorna)
if (right.stjorna) {
latestDate = compareDates(new Date(right.stjorna), latestDate)
}
if (right.kenna && new Date(right.kenna) > maxDate) {
maxDate = new Date(right.kenna)
if (right.kenna) {
latestDate = compareDates(new Date(right.kenna), latestDate)
}
}

return maxDate.toISOString()
return latestDate ? latestDate.toISOString() : null
}

const formatDateString = (
Expand Down

0 comments on commit b679c76

Please sign in to comment.