1.3.2 • Published 2 years ago

utctorelative v1.3.2

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

utcToRelative

utcToRelative is a package which converts a UTC time (in milliseconds) into a local time string which is relative to the current date. The purpose is to provide the user with an easier to understand time, such as Tomorrow, 16:00 or Sunday, 16:00 rather than 7 August 2022, 16:00.

Installation

utcToRelative can be installed by running npm i --save utctorelative.

It can be used by writing import { utcToRelative } from 'utctorelative' and calling the function utcToRelative.

Parameters

utc

This is the UTC time in milliseconds from which the relative date string will be calculated.

This is passed as an integer (e.g. 1659885783755).

The default value is the current time in milliseconds.


hourFormat

This determines whether the time will be displayed in 12-hour or 24-hour time (e.g. 4:23 pm or 16:23 respectively).

This is passed as a string of either "12" or "24".

The default value is "24".


monthFormat

This determines whether the month will be displayed in a full or concatenated form (e.g. August or Aug respectively).

This is passed as a string of either "full" or "concat".

The default value is "full".


currentTime

This is the current UTC time in milliseconds, which will be compared with the utc parameter to create a relative date string. This only needs to be defined if you do not want to use the system time as the current time.

This is passed as an integer (e.g. 1659885783755).

The default value is the current time in milliseconds, according to the system time.

Examples

For the purpose of these examples, 1659885783755 is Sunday, 7 August 2022 at 4:23 pm.

The following table shows the output of the following code when it is run on the stated days:

import { utcToRelative } from 'utctorelative';

console.log(utcToRelative(1659885783755, '12'));
DateOutput
20th July, 20217 August 2022, 4:23 pm
20th July, 20227 August, 4:23 pm
4th August, 2022Sunday, 4:23 pm
6th August, 2022Tomorrow, 4:23 pm
7th August, 2022Today, 4:23 pm
8th August, 2022Yesterday, 4:23 pm
10th August, 2022Last Sunday, 4:23 pm
20th August, 20227 August, 4:23 pm
20th August, 20237 August 2022, 4:23 pm
1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago