mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode 1a81711a85e38ccf784110568ebf3784ab9094a5 (#9161)
* Merge from vscode 1a81711a85e38ccf784110568ebf3784ab9094a5 * small spacing fix
This commit is contained in:
@@ -5,6 +5,53 @@
|
||||
|
||||
import { pad } from './strings';
|
||||
|
||||
const minute = 60;
|
||||
const hour = minute * 60;
|
||||
const day = hour * 24;
|
||||
const week = day * 7;
|
||||
const month = day * 30;
|
||||
const year = day * 365;
|
||||
|
||||
// TODO[ECA]: Localize strings
|
||||
export function fromNow(date: number | Date) {
|
||||
if (typeof date !== 'number') {
|
||||
date = date.getTime();
|
||||
}
|
||||
|
||||
const seconds = Math.round((new Date().getTime() - date) / 1000);
|
||||
if (seconds < 30) {
|
||||
return 'now';
|
||||
}
|
||||
|
||||
let value: number;
|
||||
let unit: string;
|
||||
if (seconds < minute) {
|
||||
value = seconds;
|
||||
unit = 'sec';
|
||||
} else if (seconds < hour) {
|
||||
value = Math.floor(seconds / minute);
|
||||
unit = 'min';
|
||||
} else if (seconds < day) {
|
||||
value = Math.floor(seconds / hour);
|
||||
unit = 'hr';
|
||||
} else if (seconds < week) {
|
||||
value = Math.floor(seconds / day);
|
||||
unit = 'day';
|
||||
} else if (seconds < month) {
|
||||
value = Math.floor(seconds / week);
|
||||
unit = 'wk';
|
||||
} else if (seconds < year) {
|
||||
value = Math.floor(seconds / month);
|
||||
unit = 'mo';
|
||||
} else {
|
||||
value = Math.floor(seconds / year);
|
||||
unit = 'yr';
|
||||
}
|
||||
|
||||
return `${value} ${unit}${value === 1 ? '' : 's'}`;
|
||||
|
||||
}
|
||||
|
||||
export function toLocalISOString(date: Date): string {
|
||||
return date.getFullYear() +
|
||||
'-' + pad(date.getMonth() + 1, 2) +
|
||||
|
||||
Reference in New Issue
Block a user