Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-live-clock

pvoznyuk157.4kMIT6.1.25TypeScript support: included

React Live Clock

react, date, time, clock, timezones

readme

react-live-clock npm

Gitter Dependencies Dev Dependencies

React clock with time-zones DEMO

Installation

NPM

npm install --save react react-live-clock

Don't forget to manually install peer dependencies (react) if you use npm@3.

Demo

http://pvoznyuk.github.io/react-live-clock

Usage

import React  from 'react';
import Clock from 'react-live-clock';

exports default class MyComponent extends React.Component {
    render() {
        <Clock format={'HH:mm:ss'} ticking={true} timezone={'US/Pacific'} />
    }
}

Outputs:

<time>10:15:34</time>

** Shows current time for 'US/Pacific' timezone and updates every second

React Native

React Native requires that you wrap text in a <Text> like this:

import { Text, View } from "react-native";
import Clock from "react-live-clock";

export default function ClockPage() {
  return (
    <View>
      <Text>Clock page</Text>
      <Clock element={Text} />
    </View>
  );
}

If you don't you will get the error Invariant Violation: Text strings must be rendered within a <Text> component.

Formatting

you can use any formatting from moment.js date library

Properties

Property Type Default Value Description
date timestamp or string current date Date to output, If nothing is set then it take current date.
format string 'HH:MM' Formatting from moment.js library.
locale string null Changes the language of the component via prop
filter function (date: String) => date Filtering the value before the output .
timezone string null If timezone is set, the date is show in this timezone. You can find the list. here, the TZ column.
ticking boolean false If you want the clock to be auto-updated every interval seconds.
blinking boolean, string false If you want the clock's last colon to blink. Set it to all to make them all blink.
noSsr boolean false Makes the component not render on the server to fix mismatch.
interval integer 1000 Auto-updating period for the clock. 1 second is a default value.
className string null Extra class.
style CSSProperties null CSSProperties Customized inline style .
children string null date can be set as a children prop.
onChange function ({output, previousOutput, moment}) => {} callback function on each output update

Development and testing

Currently is being developed and tested with the latest stable Node 7 on OSX and Windows.

To run example covering all ReactLiveClock features, use npm start dev, which will compile src/example/Example.js

git clone git@github.com:pvoznyuk/react-live-clock.git
cd react-live-clock
npm install
npm start dev

# then
open http://localhost:8080

Tests

# to run tests
npm start test

# to generate test coverage (./reports/coverage)
npm start test.cov

# to run end-to-end tests
npm start test.e2e

License

This software is released under the MIT license. See LICENSE for more details.

Contributors

changelog

Changelog

[6.1.25]

Bump elliptic from 6.5.7 to 6.6.0 #323

[6.1.24]

Bump elliptic from 6.5.4 to 6.5.7 (#322) Bump express from 4.19.2 to 4.21.0 (#321)

[6.1.23-beta]

Adds code to fix changing locale on the fly

[6.1.22]

Fixes problem with react-syntax-highlighter

[6.1.21]

Bump react-router-dom from 6.22.2 to 6.22.3 (#315) Bump follow-redirects from 1.15.4 to 1.15.6 (#316) Bump eslint-plugin-react from 7.34.0 to 7.34.1 (#317) Bump express from 4.18.2 to 4.19.2 (#318)

[6.1.20]

Bump eslint-plugin-react from 7.33.2 to 7.34.0 Bump es5-ext from 0.10.62 to 0.10.64 (#313) Bump react-router-dom from 6.21.1 to 6.22.2 (#314) Bump eslint from 8.56.0 to 8.57.0 (#312) Bump moment-timezone from 0.5.43 to 0.5.45 (#310) Bump follow-redirects from 1.15.3 to 1.15.4 (#306) Bump moment from 2.29.4 to 2.30.1 (#304)

[6.1.19]

Bump eslint from 8.53.0 to 8.56.0 (#301) Bump react-router-dom from 6.18.0 to 6.21.1 (#302)

[6.1.18]

Bump eslint from 8.52.0 to 8.53.0 (#294)

[6.1.17]

Bump react-router-dom from 6.15.0 to 6.18.0 (#293) Bump eslint from 8.49.0 to 8.52.0 (#291) Bump browserify-sign from 4.2.1 to 4.2.2 (#292) Adds remark dev dep Updates yarn lock

[6.1.16]

now was a number not a date object. #283 (updates typescript definition) Bump eslint from 8.47.0 to 8.49.0 #286 Adds 'use client' Directive to component #284

[6.1.15]

Bump word-wrap from 1.2.3 to 1.2.4 #273 Bump react-router-dom from 6.13.0 to 6.15.0 #279 Bump eslint from 8.42.0 to 8.47.0 #280 Bump eslint-plugin-react from 7.32.2 to 7.33.2 #281 Fix onChange event. Date param was missing in the index.d.ts file. #282

[6.1.14]

Bump eslint from 8.35.0 to 8.42.0 (#253, #256, #257, #263) Bump react-router-dom from 6.8.2 to 6.13.0 (#254, #266) Bump moment-timezone from 0.5.41 to 0.5.43 (#255)

[6.1.13]

Bump react-router-dom from 6.8.1 to 6.8.2 (#249) Bump eslint from 8.34.0 to 8.35.0 (#247) Bump moment-timezone from 0.5.40 to 0.5.41 (#248)

[6.1.12]

Bump eslint from 8.33.0 to 8.34.0 #246

[6.1.11]

Updates TypeScript thingies

[6.1.10]

Updates TypeScript thingies

[6.1.9]

Bump react-router-dom from 6.8.0 to 6.8.1 #245

[6.1.8]

Nothing Changed

[6.1.7]

Add Missing Typescript thingies

[6.1.6]

Bump eslint from 8.32.0 to 8.33.0 (#244) Bump react-router-dom from 6.7.0 to 6.8.0 (#241) Bump ua-parser-js from 0.7.28 to 0.7.33 (#242) Bump eslint-plugin-react from 7.32.1 to 7.32.2 (#243)

[6.1.5]

Fix Deprication warning about Support for defaultProps (#235)

[6.1.4]

Bump react-router-dom from 6.6.1 to 6.7.0 (#240) Bump eslint-plugin-react from 7.31.11 to 7.32.1 (#239) Bump react-moment from 1.1.2 to 1.1.3 (#237) Bump react-moment from 1.1.2 to 1.1.3 (#237)

[6.1.3]

Allow PropTypes.object for element prop

[6.1.2]

Bump eslint from 8.29.0 to 8.31.0 (#233) Bump react-router-dom from 6.4.4 to 6.6.1 (#231) Bump moment-timezone from 0.5.39 to 0.5.40 (#225) Bump express from 4.17.1 to 4.18.2 (#226) update type declaration (#232)

[6.1.1]

Bump decode-uri-component from 0.2.0 to 0.2.2 (#223) Bump react-router-dom from 6.4.3 to 6.4.4 (#221)

[6.1.0]

Moves some dependencies around to solve #77

[6.0.8]

Bump eslint from 8.27.0 to 8.28.0 (#219) Bump moment-timezone from 0.5.38 to 0.5.39 (#217) Bump eslint-plugin-react from 7.31.10 to 7.31.11

[6.0.7]

Bump eslint from 8.21.0 to 8.27.0 Bump eslint from 8.21.0 to 8.22.0 (#195) Bump eslint from 8.22.0 to 8.23.0 (#200) Bump eslint from 8.23.0 to 8.23.1 (#205) Bump eslint from 8.23.1 to 8.27.0 (#216)

Bump eslint-plugin-react from 7.30.1 to 7.31.10 Bump eslint-plugin-react from 7.30.1 to 7.31.1 (#199) Bump eslint-plugin-react from 7.31.1 to 7.31.6 (#201) Bump eslint-plugin-react from 7.31.6 to 7.31.8 (#203) Bump eslint-plugin-react from 7.31.8 to 7.31.10 (#212)

Bump moment-timezone from 0.5.34 to 0.5.38 Bump moment-timezone from 0.5.34 to 0.5.37 (#198) Bump moment-timezone from 0.5.37 to 0.5.38 (#213)

Bump react-router-dom from 6.3.0 to 6.4.3 Bump react-router-dom from 6.3.0 to 6.4.3 (#215)

[6.0.6]

Bump eslint from 8.20.0 to 8.21.0 (#194)

[6.0.5]

Bump eslint from 8.18.0 to 8.20.0 (#192) Bump moment from 2.29.3 to 2.29.4 (#190)

[6.0.4]

Bumps eslint from 8.17.0 to 8.18.0 #185

[6.0.3]

Bumps eslint-plugin-react from 7.30.0 to 7.30.1 #187 Bumps react-dom from 18.1.0 to 18.2.0 #186

[6.0.2]

fix: missing blinking in type definition. #188

[6.0.1]

Bumps react from 18.1.0 to 18.2.0 (#183)

[6.0.0]

Updates node version from 15.2.1 to 16.15.0 Bumps eslint-plugin-react from 7.29.4 to 7.30.0 (#179) Adds noSsr option to fix prop missmatch

[5.10.0]

Adds documentation about blinking Adds all option to the blinking

[5.9.0]

Fixes wrong deploy

[5.9.0]

Bumps eslint from 8.14.0 to 8.15.0 (#176) Bumps react from 18.0.0 to 18.1.0 (#174) Bumps react-dom from 18.0.0 to 18.1.0 (#175)

[5.8.2]

Bumps moment from 2.29.2 to 2.29.3 (#172)

[5.8.1]

Allows Installation on React V18

[5.8.0]

Bumps eslint from 8.11.0 to 8.13.0 (#171) Bumps moment from 2.29.1 to 2.29.2 (#170) Bumps react-moment from 1.1.1 to 1.1.2 (#169) Bumps moment from 2.29.1 to 2.29.2 (#168) Bumps react-router-dom from 6.2.2 to 6.3.0 (#166)

[5.7.0]

Bumps eslint from 8.10.0 to 8.11.0 #163 Bumps react-syntax-highlighter from 15.4.5 to 15.5.0 #162 Bumps react-router-dom from 6.2.1 to 6.2.2 #159 Bumps eslint-plugin-react from 7.29.2 to 7.29.4 #161 Bumps react-router-dom from 6.2.1 to 6.2.2 #159

[5.6.1]

Fixes proptype validation

[5.6.0]

Adds Element passthrough prop Bumps eslint from 8.6.0 to 8.7.0 #149 Bumps follow-redirects from 1.13.3 to 1.14.7 #148 Relaces react-highlight.js for react-syntax-highlighter

[5.5.1]

Rebuilds to insure proper updates

[5.5.0]

Adds suport back for custom Date in the past or future that ticks

[5.4.2]

Bump react-router-dom from 5.3.0 to 6.2.1 #141

[5.4.1]

Bumps prop-types from 15.7.2 to 15.8.1 #146 Bumps eslint from 8.0.1 to 8.6.0 #145 Bumps eslint-plugin-react from 7.26.1 to 7.28.0 #144 Bumps moment-timezone from 0.5.33 to 0.5.34 #130

[5.4.0]

Adds onReady Prop

[5.3.3]

Corrects Documentation #129

[5.3.2]

Update the example page to show how to set a language + sort props destruction asc in Component.js (#123)

[5.3.1]

Updates typescript index

[5.3.0]

Adds Class name to typescript Updates Dependencies

[5.2.0]

Adds locale prop

[5.1.0]

Adds Filter Prop Changes from NPM to YARN

[5.0.13]

Bumps .nvmrc version from 7 to 15.2.1 Corects Cspell words order Adds suport for react 17

[5.0.12]

Bump eslint from 7.12.1 to 7.13.0 Bump moment-timezone from 0.5.31 to 0.5.32

[5.0.11]

Bump eslint from 7.12.0 to 7.12.1

[5.0.10]

Bump eslint from 7.11.0 to 7.12.0 Bump eslint-plugin-react from 7.21.4 to 7.21.5

[5.x.x]

This was a rewrite of the program to use react hooks

[4.0.5] - 2020-03-16

Fixes

  • Fixes ticking stoping caused in 4.0.4

Adds

  • Nothing

Removes

  • Nothing

[4.0.4] - 2020-03-11

Fixes

  • Trying to update state on unmounted component #36

Adds

  • Nothing

Removes

  • Nothing

[4.0.1] - 2020-01-20

Fixes

  • Over rendering
  • Runing onChange too often

Adds

  • typescript definition

Removes

  • Nothing

[4.0.0-beta] - 2020-01-27

As of version 4.0.0 react live lock uses react hooks.

Minimum requirement(s):

  • "react": "^16.8"