-
-
Save martinandersen3d/0e9e51b6e02ab013f7fe69ef74873839 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>LuxonJS The Modern MomentJS</title> | |
<meta name="viewport" content="width=device-width"> | |
<style> | |
#output{ | |
font-size: 2rem; | |
} | |
</style> | |
</head> | |
<body> | |
<header> | |
<h1>Luxon JS Library</h1> | |
<h2>The Evolution of MomentJS</h2> | |
</header> | |
<main> | |
<div id="output"></div> | |
</main> | |
<script src="luxon.min.js"></script> | |
<script> | |
let output = document.getElementById('output'); | |
//output.textContent = JSON.stringify(luxon.DateTime.DATETIME_FULL); | |
let DateTime = luxon.DateTime; | |
//base object in Luxon | |
//DateTime | |
// - diff(dateTime), diffNow(), equals(dateTime), hasSame(dateTime, unit), | |
// minus(duration|object|ms), plus(duration|object|ms), setLocale(), setZone(), | |
// toUTC() , until(DateTime) | |
// https://moment.github.io/luxon/docs/class/src/datetime.js~DateTime.html | |
let today = DateTime.local(); | |
let f = {month: 'long', day: '2-digit'}; | |
let m = today.get('month'); | |
let tz = today.zoneName; | |
//output.textContent = tz; | |
let newDt = today.set({month: 12}); | |
//for people - toLocaleString | |
//output.textContent = newDt.setLocale('de').toLocaleString(f); | |
output.textContent = newDt.setLocale('fr-CA').toLocaleString(f); | |
//output.textContent = today.toLocaleString(); | |
//output.textContent = today.toLocaleString(DateTime.DATETIME_FULL_WITH_SECONDS); | |
//output.textContent = today.toFormat('yyyy LLL dd'); | |
//for computers | |
// - toISO, toBSON, toObject, toJSDate, toJSON, toSQL, toMillis | |
console.log( newDt.toISO() ); | |
//Duration | |
// - A generic period of time | |
// - fromISO, fromMillis, fromObject, days, minutes, years... | |
// - as('days'), equals(duration), minus(duration | Obj), plus() | |
// https://moment.github.io/luxon/docs/class/src/duration.js~Duration.html | |
let dur = luxon.Duration.fromMillis(20000); | |
let hurdur = luxon.Duration.fromMillis(20000); | |
console.warn( dur.equals(hurdur) ); | |
// Interval | |
// - half-open interval of time. It contains 2 endpoints. | |
// - start or end point plus a duration | |
// - fromDateTimes(start, end), after(start, Duration), | |
// before(end, Duration), equals(Interval), overlaps(Interval), | |
// abutsEnd(Interval), abutsStart(Interval), engulfs(Interval) | |
// - .start, .end, .isValid | |
// https://moment.github.io/luxon/docs/class/src/interval.js~Interval.html | |
// Info - Static Methods | |
// - hasDST, months, monthsFormat, weekdays, weekdaysFormat | |
// https://moment.github.io/luxon/docs/class/src/info.js~Info.html | |
today.setZone('America/Regina'); | |
console.log( luxon.Info.hasDST('America/Regina') ); | |
console.log( luxon.Info.isValidIANAZone('America/Regina') ); | |
console.log( luxon.Info.monthsFormat() ); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment