5.1.2 • Published 2 years ago

@bbc/psammead-timestamp-container v5.1.2

Weekly downloads
1,279
License
Apache-2.0
Repository
github
Last release
2 years ago

psammead-timestamp-container - Known Vulnerabilities Dependency Status peerDependencies Status npm version Storybook GitHub license PRs Welcome

Description

psammead-timestamp-container is a React container that offers relative and absolute times, with timezone support - using moment-timezone. Relative times are currently hard-coded to English (e.g. 3 minutes ago). psammead-timestamp-container returns a single time element.

Exports

/utilities - exports functions for dealing with timestamps.

When to use this component

psammead-timestamp-container is intended to be used when a single time DOM element that has the possibility of having varying time formats and timezones is required.

Installation

npm install @bbc/psammead-timestamp-container

Props

ArgumentTypeRequiredDefaultExample
timestampnumber or stringYesN/A1530947227000, '2012-03-08T12:17:24.000Z'
dateTimeFormatstringYesN/AYYYY-MM-DD
isRelativebooleanNofalsetrue
formatstringNonullD MMMM YYYY, HH:mm z
timezonestringNo'Europe/London''Europe/London'
paddingbooleanNotruefalse
prefixstringNonullUpdated
suffixstringNonullThis is a suffix
scriptobjectYesN/A{ canon: { groupA: { fontSize: '28', lineHeight: '32',}, groupB: { fontSize: '32', lineHeight: '36', }, groupD: { fontSize: '44', lineHeight: '48', }, }, trafalgar: { groupA: { fontSize: '20', lineHeight: '24', }, groupB: { fontSize: '24', lineHeight: '28', }, groupD: { fontSize: '32', lineHeight: '36', }, }, }
localestringnonullen
servicestringyesnullnews
altCalendarobjectnonullSee the jalaali calendar in psammead-calendars as an example

locale should be a momentjs locale.

Usage

import { latin } from '@bbc/gel-foundations/scripts';

const WrappingContainer = () => (
  <Timestamp
    timestamp={1530947227000}
    dateTimeFormat="YYYY-MM-DD"
    isRelative={false}
    format="D MMMM YYYY"
    timezone="Europe/London"
    prefix="Updated"
    suffix="."
    script={latin}
    locale="en"
  />
);

Utilities

formatDuration

import { formatDuration } from '@bbc/psammead-timestamp-container/utilities';

const localisedDuration = formatDuration({ duration: 'PTM30', locale: 'my' });
const customFormatDuration = formatDuration({
  duration: 'PTM30',
  format: 'mm,ss',
});
ArgumentTypeRequiredDefaultExample
durationstringYesN/APTH1M29S30 Duration string as specified by ISO 8601 standard.
formatstringNomm:ss, or h:mm:ss if in hoursmm,ss
localestringNoen-gbfr

localisedMoment

import { localisedMoment } from '@bbc/psammead-timestamp-container/utilities';

const localisedMoment = localisedMoment({ locale, timestamp });
ArgumentTypeRequiredDefaultExample
timestampnumber or stringYesN/A1539969006000 (Unix timestamp), '2012-03-08T12:17:24.000Z' (ISO8601 string)
localestringYesN/Afr

formatUnixTimestamp

import { localiseTimestamp } from '@bbc/psammead-timestamp-container/utilities';

const formattedTime = formatUnixTimestamp({
  format,
  isRelative,
  locale,
  timestamp,
  timezone,
});
ArgumentTypeRequiredDefaultExample
formatstringNo'LL, LT z''D MMMM YYYY z' a moment format string
isRelativebooleanYesN/Atrue When true, formats in relative time
localestringYesN/Afr Moment locale
timestampnumber or stringYesN/A1539969006000 (Unix timestamp), '2012-03-08T12:17:24.000Z' (ISO8601 string)
timezonestringYesN/A'GMT', 'Asia/Seoul' see (moment-timezone documentation)https://momentjs.com/timezone/

Accessibility notes

The usage of the semantic time element within psammead-timestamp component can result in strange behaviours when using assistive technology such as VoiceOver for iOS. Specifically, it results in a "text splitting" behaviour, where any text in the prefix is read out, but the value inside the semantic time element require an additional swipe before being read out.

However, as we heavily encourage the use of this semantic element, and want to ensure it's usage is in line with the W3C examples, we feel this compromise is necessary.

Roadmap

Currently, this package only supports relative time in English. The plan is to make this package more suitable for use on World Service sites by including logic to render relative time in multiple languages.

Contributing

Psammead is completely open source. We are grateful for any contributions, whether they be new components, bug fixes or general improvements. Please see our primary contributing guide which can be found at the root of the Psammead respository.

Code of Conduct

We welcome feedback and help on this work. By participating in this project, you agree to abide by the code of conduct. Please take a moment to read it.

License

Psammead is Apache 2.0 licensed.

5.1.2

2 years ago

5.1.1

2 years ago

5.1.0

2 years ago

5.0.40

2 years ago

5.0.39

3 years ago

5.0.38

3 years ago

5.0.35

3 years ago

5.0.36

3 years ago

5.0.37

3 years ago

5.0.33

3 years ago

5.0.34

3 years ago

5.0.32

3 years ago

5.0.31

3 years ago

5.0.30

3 years ago

5.0.29

3 years ago

5.0.28

3 years ago

5.0.27

3 years ago

5.0.26

3 years ago

5.0.25

3 years ago

5.0.24

3 years ago

5.0.23

3 years ago

5.0.22

3 years ago

5.0.21

3 years ago

5.0.20

3 years ago

5.0.18

3 years ago

5.0.19

3 years ago

5.0.17

3 years ago

5.0.16

3 years ago

5.0.15

3 years ago

5.0.14

3 years ago

5.0.13

3 years ago

5.0.12

3 years ago

5.0.11

3 years ago

5.0.10

3 years ago

5.0.9

4 years ago

5.0.8

4 years ago

5.0.7

4 years ago

5.0.6

4 years ago

5.0.5

4 years ago

5.0.4

4 years ago

5.0.3

4 years ago

5.0.2

4 years ago

5.0.0-alpha.0

4 years ago

4.0.13

4 years ago

4.0.12

4 years ago

4.0.11

4 years ago

4.0.10

4 years ago

4.0.9

4 years ago

4.0.7

4 years ago

4.0.8

4 years ago

4.0.6

4 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.7.15

4 years ago

2.7.14

4 years ago

2.7.13

4 years ago

2.7.12

4 years ago

2.7.11

4 years ago

2.7.10

4 years ago

2.7.9

4 years ago

2.7.8

4 years ago

2.7.7

4 years ago

2.7.6

4 years ago

2.7.5

4 years ago

2.7.4

4 years ago

2.7.3

4 years ago

2.7.2

4 years ago

2.7.1

4 years ago

2.7.0

4 years ago

2.6.21

4 years ago

2.6.20

4 years ago

2.6.19

4 years ago

2.6.18

4 years ago

2.6.17

4 years ago

2.6.16

4 years ago

2.6.15

4 years ago

2.6.14

4 years ago

2.6.13

4 years ago

2.6.12

4 years ago

2.6.11

4 years ago

2.6.10

4 years ago

2.6.9

4 years ago

2.6.8

5 years ago

2.6.7

5 years ago

2.6.6

5 years ago

2.6.5

5 years ago

2.6.4

5 years ago

2.6.3

5 years ago

2.6.2

5 years ago

2.6.1

5 years ago

2.6.0

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.22

5 years ago

2.4.21

5 years ago

2.4.20

5 years ago

2.4.19

5 years ago

2.4.18

5 years ago

2.4.17

5 years ago

2.4.16

5 years ago

2.4.15

5 years ago

2.4.14

5 years ago

2.4.13

5 years ago

2.4.12

5 years ago

2.4.11

5 years ago

2.4.10

5 years ago

2.4.9

5 years ago

2.4.8

5 years ago

2.4.7

5 years ago

2.4.6

5 years ago

2.4.5

5 years ago

2.4.4

5 years ago

2.4.3

5 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.6

5 years ago

2.3.5

5 years ago

2.3.4

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.2.6

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago