npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bbc/psammead-timestamp-container

v5.1.2

Published

React Timestamp container for relative and absolute times, using moment-timezone

Downloads

760

Readme

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

| Argument | Type | Required | Default | Example | |-----------|---------------------|----------|---------|-----------------| | timestamp | number or string | Yes | N/A | 1530947227000, '2012-03-08T12:17:24.000Z' | | dateTimeFormat | string | Yes | N/A | YYYY-MM-DD | | isRelative | boolean | No | false | true | | format | string | No | null | D MMMM YYYY, HH:mm z | | timezone | string | No | 'Europe/London' | 'Europe/London' | | padding | boolean | No | true | false | | prefix | string | No | null | Updated | | suffix | string | No | null | This is a suffix | | script | object | Yes | N/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', }, }, } | | locale | string | no | null | en | | service | string | yes | null | news | | altCalendar | object | no | null | See 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',
});

| Argument | Type | Required | Default | Example | |-----------|-------------|----------|---------|-----------------| | duration | string | Yes | N/A | PTH1M29S30 Duration string as specified by ISO 8601 standard. | | format | string | No | mm:ss, or h:mm:ss if in hours | mm,ss | | locale | string | No | en-gb | fr |

localisedMoment

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

const localisedMoment = localisedMoment({ locale, timestamp });

| Argument | Type | Required | Default | Example | |-----------|-------------|----------|---------|-----------------| | timestamp | number or string | Yes | N/A | 1539969006000 (Unix timestamp), '2012-03-08T12:17:24.000Z' (ISO8601 string) | | locale | string | Yes | N/A | fr |

formatUnixTimestamp

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

const formattedTime = formatUnixTimestamp({
  format,
  isRelative,
  locale,
  timestamp,
  timezone,
});

| Argument | Type | Required | Default | Example | |-----------|-------------|----------|---------|-----------------| | format | string | No | 'LL, LT z' | 'D MMMM YYYY z' a moment format string | | isRelative | boolean | Yes | N/A | true When true, formats in relative time | | locale | string | Yes | N/A | fr Moment locale | | timestamp | number or string | Yes | N/A | 1539969006000 (Unix timestamp), '2012-03-08T12:17:24.000Z' (ISO8601 string) | | timezone | string | Yes | N/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.