🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

netlify-cms-widget-datetimezone

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

netlify-cms-widget-datetimezone

DateTime with Timezone Netlify CMS Widget

latest
Source
npmnpm
Version
0.9.10
Version published
Maintainers
1
Created
Source

Netlify CMS Widget DateTimeZone

NPM npm

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.

Netlify CMS Widget DateTimeZone

Install

Add the package to your project.

yarn add netlify-cms-widget-datetimezone

Configure Netlify CMS to use the widget.

// import libs
import CMS, { init } from "netlify-cms-app";
import {
	DateTimeZoneControl,
	DateTimeZonePreview,
} from "netlify-cms-widget-datetimezone";

// register datetimezone widget
CMS.registerWidget("datetimezone", DateTimeZoneControl, DateTimeZonePreview);

Add the widget to a field.

fields:
  - { name: "datetimezone", label: "Start Time", widget: "datetimezone" }

Example Component

// import libs
import React from 'react';
import { DateTime } from "luxon";

/**
 * DateComponent
 * @param {string} datetime
 * @param {string} timezone
 * @param {string} locale
 */
const DateComponent = ({ datetime, timezone, locale }) => {

  // get the entry datetime and timezone
  const datetimeOriginal = DateTime
    .fromISO(datetime, { zone: timezone })

  // display datetime as a local date to your visitors
  const datetimeLocal = DateTime
    .fromISO(datetime, {
      zone: Intl.DateTimeFormat().resolvedOptions().timeZone
    })

  // display datetime in an i18n localized format
  const datetimeLocalized = DateTime
    .fromISO(dateTime, {
      zone: { zone: 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

Keywords

netlify

FAQs

Package last updated on 14 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts