Luxon playground

Luxonであそぶ用

by gentouru

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/2.0.2/luxon.min.js"></script>

JavaScript

const DateTime = luxon.DateTime;

// weird
const beforeTimeChange = DateTime.fromISO('2021-10-15T00:00:00Z', {zone: 'Europe/Andorra'});
const afterTimeChange = DateTime.fromISO('2021-11-15T00:00:00Z', {zone: 'Europe/Andorra'});
console.log(afterTimeChange.diff(beforeTimeChange, 'days').days);
console.log(afterTimeChange.diff(beforeTimeChange, 'hours').hours / 24);

// ok
const beforeTimeChangeOK = DateTime.fromISO('2021-10-15T00:00:00Z', {zone: 'utc'});
const afterTimeChangeOK = DateTime.fromISO('2021-11-15T00:00:00Z', {zone: 'utc'});
console.log(afterTimeChangeOK.diff(beforeTimeChangeOK, 'days').days);
console.log(afterTimeChangeOK.diff(beforeTimeChangeOK, 'hours').hours / 24);

const bDay = DateTime.fromISO("2019-09-01");
console.log("BDAY:" + bDay + new Date(bDay))
const cutOff = DateTime.fromISO("2023-09-01");
console.log("CUTOFF:" + bDay + new Date(cutOff))
const diff = cutOff.diff(bDay, ["years", "months", "days"]).toObject();
console.log(diff)