Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 26x 26x 59x 26x 26x 11x 26x 1177x 113x 113x 11x 113x 59x 1177x | // format a date
import { Timestamp } from "google-protobuf/google/protobuf/timestamp_pb";
import { Dayjs } from "./dayjs";
import { dayMillis } from "./timeAgo";
const monthFormatter = (locale: string) =>
new Intl.DateTimeFormat(locale, {
month: "short",
year: "numeric",
});
const dateTimeFormatter = (locale: string) =>
new Intl.DateTimeFormat(locale, {
dateStyle: "medium",
timeStyle: "medium",
});
const dateFormatter = (locale: string) =>
new Intl.DateTimeFormat(locale, {
year: "numeric",
month: "short",
day: "2-digit",
});
const numNights = (date1: string, date2: string) => {
const diffTime = Date.parse(date1) - Date.parse(date2);
const diffDays = Math.ceil(diffTime / dayMillis);
return diffDays;
};
function timestamp2Date(timestamp: Timestamp.AsObject): Date {
return new Date(Math.floor(timestamp.seconds * 1e3 + timestamp.nanos / 1e6));
}
function isSameDate(date1: Dayjs, date2: Dayjs): boolean {
return (
date1.month() === date2.month() &&
date1.year() === date2.year() &&
date1.date() === date2.date()
);
}
/** Compares whether date1 is equal to or in the future of date2 */
function isSameOrFutureDate(date1: Dayjs, date2: Dayjs): boolean {
return isSameDate(date1, date2) || date1.isAfter(date2);
}
export {
dateFormatter,
dateTimeFormatter,
isSameOrFutureDate,
monthFormatter,
numNights,
timestamp2Date,
};
|