Netlify CMS Widget DateTimeZone
This widget provides the datetimezone widget to store date, time, and timezone data for working with dates and times internationally. It was developed for conference.jamfire.io and was designed to use with Luxon.
Install
Add the package to your project.
yarn add netlify-cms-widget-datetimezone
Configure Netlify CMS to use the widget.
import CMS, { init } from "netlify-cms-app"
import { DateTimeZoneControl, DateTimeZonePreview } from "netlify-cms-widget-datetimezone"
CMS.registerWidget("datetimezone", DateTimeZoneControl, DateTimeZonePreview)
Add the widget to a field.
fields:
- { name: 'datetimezone', label: 'Start Time', widget: 'datetimezone' }
Example Component
import React from 'react';
import { DateTime } from "luxon";
const DateComponent = ({ datetime, timezone, locale }) => {
const datetimeOriginal = DateTime
.fromISO(value.datetime, { zone: value.timezone })
const datetimeLocal = DateTime
.fromISO(value.datetime, {
zone: Intl.DateTimeFormat().resolvedOptions().timeZone
})
const datetimeLocalized = DateTime
.fromISO(value.dateTime, {
zone: { zone: value.timezone }
})
.setLocale(locale))
return(
<p>
Entry DateTime: {datetime.toLocaleString(DateTime.DATETIME_FULL)}<br />
Local DateTime: {datetimeLocal.toLocaleString(DateTime.DATETIME_FULL)}<br />
Localized DateTime: {datetimeLocalized.toLocaleString(DateTime.DATETIME_FULL)}
</p>
)
}
Changelog
See CHANGELOG.md
Contributing
See CONTRIBUTING.md