Apply prettier formatting

This commit is contained in:
Michael Weimann 2022-12-12 12:24:14 +01:00
parent 1cac306093
commit 526645c791
No known key found for this signature in database
GPG key ID: 53F535A266BB9584
1576 changed files with 65385 additions and 62478 deletions

View file

@ -16,45 +16,37 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { _t } from './languageHandler';
import { _t } from "./languageHandler";
function getDaysArray(): string[] {
return [
_t('Sun'),
_t('Mon'),
_t('Tue'),
_t('Wed'),
_t('Thu'),
_t('Fri'),
_t('Sat'),
];
return [_t("Sun"), _t("Mon"), _t("Tue"), _t("Wed"), _t("Thu"), _t("Fri"), _t("Sat")];
}
function getMonthsArray(): string[] {
return [
_t('Jan'),
_t('Feb'),
_t('Mar'),
_t('Apr'),
_t('May'),
_t('Jun'),
_t('Jul'),
_t('Aug'),
_t('Sep'),
_t('Oct'),
_t('Nov'),
_t('Dec'),
_t("Jan"),
_t("Feb"),
_t("Mar"),
_t("Apr"),
_t("May"),
_t("Jun"),
_t("Jul"),
_t("Aug"),
_t("Sep"),
_t("Oct"),
_t("Nov"),
_t("Dec"),
];
}
function pad(n: number): string {
return (n < 10 ? '0' : '') + n;
return (n < 10 ? "0" : "") + n;
}
function twelveHourTime(date: Date, showSeconds = false): string {
let hours = date.getHours() % 12;
const minutes = pad(date.getMinutes());
const ampm = date.getHours() >= 12 ? _t('PM') : _t('AM');
const ampm = date.getHours() >= 12 ? _t("PM") : _t("AM");
hours = hours ? hours : 12; // convert 0 -> 12
if (showSeconds) {
const seconds = pad(date.getSeconds());
@ -71,13 +63,13 @@ export function formatDate(date: Date, showTwelveHour = false): string {
return formatTime(date, showTwelveHour);
} else if (now.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) {
// TODO: use standard date localize function provided in counterpart
return _t('%(weekDayName)s %(time)s', {
return _t("%(weekDayName)s %(time)s", {
weekDayName: days[date.getDay()],
time: formatTime(date, showTwelveHour),
});
} else if (now.getFullYear() === date.getFullYear()) {
// TODO: use standard date localize function provided in counterpart
return _t('%(weekDayName)s, %(monthName)s %(day)s %(time)s', {
return _t("%(weekDayName)s, %(monthName)s %(day)s %(time)s", {
weekDayName: days[date.getDay()],
monthName: months[date.getMonth()],
day: date.getDate(),
@ -90,7 +82,7 @@ export function formatDate(date: Date, showTwelveHour = false): string {
export function formatFullDateNoTime(date: Date): string {
const days = getDaysArray();
const months = getMonthsArray();
return _t('%(weekDayName)s, %(monthName)s %(day)s %(fullYear)s', {
return _t("%(weekDayName)s, %(monthName)s %(day)s %(fullYear)s", {
weekDayName: days[date.getDay()],
monthName: months[date.getMonth()],
day: date.getDate(),
@ -101,7 +93,7 @@ export function formatFullDateNoTime(date: Date): string {
export function formatFullDate(date: Date, showTwelveHour = false, showSeconds = true): string {
const days = getDaysArray();
const months = getMonthsArray();
return _t('%(weekDayName)s, %(monthName)s %(day)s %(fullYear)s %(time)s', {
return _t("%(weekDayName)s, %(monthName)s %(day)s %(fullYear)s %(time)s", {
weekDayName: days[date.getDay()],
monthName: months[date.getMonth()],
day: date.getDate(),
@ -114,23 +106,29 @@ export function formatFullTime(date: Date, showTwelveHour = false): string {
if (showTwelveHour) {
return twelveHourTime(date, true);
}
return pad(date.getHours()) + ':' + pad(date.getMinutes()) + ':' + pad(date.getSeconds());
return pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds());
}
export function formatTime(date: Date, showTwelveHour = false): string {
if (showTwelveHour) {
return twelveHourTime(date);
}
return pad(date.getHours()) + ':' + pad(date.getMinutes());
return pad(date.getHours()) + ":" + pad(date.getMinutes());
}
export function formatSeconds(inSeconds: number): string {
const isNegative = inSeconds < 0;
inSeconds = Math.abs(inSeconds);
const hours = Math.floor(inSeconds / (60 * 60)).toFixed(0).padStart(2, '0');
const minutes = Math.floor((inSeconds % (60 * 60)) / 60).toFixed(0).padStart(2, '0');
const seconds = Math.floor(((inSeconds % (60 * 60)) % 60)).toFixed(0).padStart(2, '0');
const hours = Math.floor(inSeconds / (60 * 60))
.toFixed(0)
.padStart(2, "0");
const minutes = Math.floor((inSeconds % (60 * 60)) / 60)
.toFixed(0)
.padStart(2, "0");
const seconds = Math.floor((inSeconds % (60 * 60)) % 60)
.toFixed(0)
.padStart(2, "0");
let output = "";
if (hours !== "00") output += `${hours}:`;
@ -146,7 +144,7 @@ export function formatSeconds(inSeconds: number): string {
export function formatTimeLeft(inSeconds: number): string {
const hours = Math.floor(inSeconds / (60 * 60)).toFixed(0);
const minutes = Math.floor((inSeconds % (60 * 60)) / 60).toFixed(0);
const seconds = Math.floor(((inSeconds % (60 * 60)) % 60)).toFixed(0);
const seconds = Math.floor((inSeconds % (60 * 60)) % 60).toFixed(0);
if (hours !== "0") {
return _t("%(hours)sh %(minutes)sm %(seconds)ss left", {
@ -192,8 +190,8 @@ export function wantsDateSeparator(prevEventDate: Date, nextEventDate: Date): bo
export function formatFullDateNoDay(date: Date) {
return _t("%(date)s at %(time)s", {
date: date.toLocaleDateString().replace(/\//g, '-'),
time: date.toLocaleTimeString().replace(/:/g, '-'),
date: date.toLocaleDateString().replace(/\//g, "-"),
time: date.toLocaleTimeString().replace(/:/g, "-"),
});
}
@ -208,13 +206,7 @@ export function formatFullDateNoDayISO(date: Date): string {
}
export function formatFullDateNoDayNoTime(date: Date) {
return (
date.getFullYear() +
"/" +
pad(date.getMonth() + 1) +
"/" +
pad(date.getDate())
);
return date.getFullYear() + "/" + pad(date.getMonth() + 1) + "/" + pad(date.getDate());
}
export function formatRelativeTime(date: Date, showTwelveHour = false): string {
@ -244,15 +236,15 @@ const DAY_MS = HOUR_MS * 24;
*/
export function formatDuration(durationMs: number): string {
if (durationMs >= DAY_MS) {
return _t('%(value)sd', { value: Math.round(durationMs / DAY_MS) });
return _t("%(value)sd", { value: Math.round(durationMs / DAY_MS) });
}
if (durationMs >= HOUR_MS) {
return _t('%(value)sh', { value: Math.round(durationMs / HOUR_MS) });
return _t("%(value)sh", { value: Math.round(durationMs / HOUR_MS) });
}
if (durationMs >= MINUTE_MS) {
return _t('%(value)sm', { value: Math.round(durationMs / MINUTE_MS) });
return _t("%(value)sm", { value: Math.round(durationMs / MINUTE_MS) });
}
return _t('%(value)ss', { value: Math.round(durationMs / 1000) });
return _t("%(value)ss", { value: Math.round(durationMs / 1000) });
}
/**
@ -267,13 +259,13 @@ export function formatPreciseDuration(durationMs: number): string {
const seconds = Math.floor((durationMs % MINUTE_MS) / 1000);
if (days > 0) {
return _t('%(days)sd %(hours)sh %(minutes)sm %(seconds)ss', { days, hours, minutes, seconds });
return _t("%(days)sd %(hours)sh %(minutes)sm %(seconds)ss", { days, hours, minutes, seconds });
}
if (hours > 0) {
return _t('%(hours)sh %(minutes)sm %(seconds)ss', { hours, minutes, seconds });
return _t("%(hours)sh %(minutes)sm %(seconds)ss", { hours, minutes, seconds });
}
if (minutes > 0) {
return _t('%(minutes)sm %(seconds)ss', { minutes, seconds });
return _t("%(minutes)sm %(seconds)ss", { minutes, seconds });
}
return _t('%(value)ss', { value: seconds });
return _t("%(value)ss", { value: seconds });
}