1
>
/*---------------------------------------------------------------------------------------------
date.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { localize } from '../../nls.js';
7
>
import { Lazy } from './lazy.js';
8
>
import { LANGUAGE_DEFAULT } from './platform.js';
9
>
10
>
const minute = 60;
11
>
const hour = minute * 60;
12
>
const day = hour * 24;
13
>
const week = day * 7;
14
>
const month = day * 30;
15
>
const year = day * 365;
16
>
17
>
/**
18
>
* Create a localized difference of the time between now and the specified date.
19
>
* @param date The date to generate the difference from.
20
>
* @param appendAgoLabel Whether to append the " ago" to the end.
21
>
* @param useFullTimeWords Whether to use full words (eg. seconds) instead of
22
>
* shortened (eg. secs).
23
>
* @param disallowNow Whether to disallow the string "now" when the difference
24
>
* is less than 30 seconds.
25
>
*/
26
>
export function fromNow(date: number | Date, appendAgoLabel?: boolean, useFullTimeWords?: boolean, disallowNow?: boolean): string {
27
if (typeof date === 'undefined') {
28
return localize('date.fromNow.unknown', 'unknown');