Convert utils to Typescript
This commit is contained in:
parent
b2d9dd7214
commit
c8b3acb7e4
2 changed files with 14 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
Copyright 2019, 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -22,7 +22,7 @@ import url from "url";
|
||||||
* @param {string} u The url to be abbreviated
|
* @param {string} u The url to be abbreviated
|
||||||
* @returns {string} The abbreviated url
|
* @returns {string} The abbreviated url
|
||||||
*/
|
*/
|
||||||
export function abbreviateUrl(u) {
|
export function abbreviateUrl(u: string): string {
|
||||||
if (!u) return '';
|
if (!u) return '';
|
||||||
|
|
||||||
const parsedUrl = url.parse(u);
|
const parsedUrl = url.parse(u);
|
||||||
|
@ -37,7 +37,7 @@ export function abbreviateUrl(u) {
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unabbreviateUrl(u) {
|
export function unabbreviateUrl(u: string): string {
|
||||||
if (!u) return '';
|
if (!u) return '';
|
||||||
|
|
||||||
let longUrl = u;
|
let longUrl = u;
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -16,12 +16,6 @@ limitations under the License.
|
||||||
|
|
||||||
import { _t } from "../languageHandler";
|
import { _t } from "../languageHandler";
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a timestamp into human-readable, translated, text.
|
|
||||||
* @param {number} timeMillis The time in millis to compare against.
|
|
||||||
* @returns {string} The humanized time.
|
|
||||||
*/
|
|
||||||
export function humanizeTime(timeMillis) {
|
|
||||||
// These are the constants we use for when to break the text
|
// These are the constants we use for when to break the text
|
||||||
const MILLISECONDS_RECENT = 15000;
|
const MILLISECONDS_RECENT = 15000;
|
||||||
const MILLISECONDS_1_MIN = 75000;
|
const MILLISECONDS_1_MIN = 75000;
|
||||||
|
@ -30,6 +24,12 @@ export function humanizeTime(timeMillis) {
|
||||||
const HOURS_UNDER_1_DAY = 23;
|
const HOURS_UNDER_1_DAY = 23;
|
||||||
const HOURS_1_DAY = 26;
|
const HOURS_1_DAY = 26;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a timestamp into human-readable, translated, text.
|
||||||
|
* @param {number} timeMillis The time in millis to compare against.
|
||||||
|
* @returns {string} The humanized time.
|
||||||
|
*/
|
||||||
|
export function humanizeTime(timeMillis: number): string {
|
||||||
const now = (new Date()).getTime();
|
const now = (new Date()).getTime();
|
||||||
let msAgo = now - timeMillis;
|
let msAgo = now - timeMillis;
|
||||||
const minutes = Math.abs(Math.ceil(msAgo / 60000));
|
const minutes = Math.abs(Math.ceil(msAgo / 60000));
|
Loading…
Add table
Add a link
Reference in a new issue