fix: time-format-inconsistency (#120)

* fix off by one date display

* display dates in consistent format

* use token or ci
This commit is contained in:
Hayden 2022-10-31 18:43:30 -08:00 committed by GitHub
parent cd82fe0d89
commit 4a9d21d604
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 20 deletions

View file

@ -1,16 +1,10 @@
import { Requests } from "../../requests";
// <
// TGetResult,
// TPostData,
// TPostResult,
// TPutData = TPostData,
// TPutResult = TPostResult,
// TDeleteResult = void
// >
type BaseApiType = {
createdAt: string;
updatedAt: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
};
export function hasKey(obj: object, key: string): obj is Required<BaseApiType> {
@ -20,10 +14,11 @@ export function hasKey(obj: object, key: string): obj is Required<BaseApiType> {
export function parseDate<T>(obj: T, keys: Array<keyof T> = []): T {
const result = { ...obj };
[...keys, "createdAt", "updatedAt"].forEach(key => {
// @ts-ignore - we are checking for the key above
// @ts-ignore - TS doesn't know that we're checking for the key above
if (hasKey(result, key)) {
// @ts-ignore - we are guarding against this above
result[key] = new Date(result[key]);
// Ensure date like format YYYY/MM/DD - otherwise results will be 1 day off
const dateStr: string = result[key].split("T")[0].replace(/-/g, "/");
result[key] = new Date(dateStr);
}
});