0.2.1 • Published 10 years ago

finn-date-formatter v0.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

FINN date formatter

THIS PROJECT IS AN ONGOING EXPERIMENT. No support can be expected.

npm package for formatting Dates, FINN style. From the styleguide (November 6, 2015):

Dates and time

Specified time

In Finn we display time and dates the following way:

  • 11. okt 2015 (without time)
  • 11. okt 2015 23:59 (with time)

Relative time

If it's less than 3 days you can show relative time like this:

  • Et øyeblikk siden
  • 1 minutt siden
  • 59 minutter siden
  • 1 time siden
  • 23 timer siden
  • 1 dag siden
  • 2 dager siden

Installation

Use the npm.finntech.no registry by adding the following to your .npmrc file:

# download all packages from the FINN npm registry
registry=http://npm.finntech.no/

Then install via npm:

npm install --save finn-date-formatter

Usage

The module exports a default function format(date: Date[, options: Object]).

Example

import formatDate from 'finn-date-formatter';

const date = new Date('October 11, 2015 03:23:00');

// 11. okt 2015
format(date);

// 11. okt 2015 03:23
format(date, {
  showTime: true
});

// 11.10.2015 03:23
format(date, {
  monthAsNumber: true,
  showTime: true,
});

// Et øyeblikk siden
const now = new Date();
format(date);

See the unit tests in test/ for further usage.

Available options

  • boolean showTime: Appends time on the format HH:MM
  • boolean monthAsNumber: Displays 11.10.2015 instead of 11. okt 2015

Development