Skip to content

Commit

Permalink
feat: convert server time to local time for last analytics runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Nov 6, 2024
1 parent d32cfcb commit ba2f3f2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dotenv": "^16.4.5",
"font-awesome": "4.7.0",
"moment": "^2.30.1",
"moment-timezone": "^0.5.46",
"purify-ts": "1.2.0",
"purify-ts-extra-codec": "0.6.0",
"react": "^18.2.0",
Expand Down
21 changes: 10 additions & 11 deletions src/data/repositories/SystemD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { D2Api } from "@eyeseetea/d2-api/2.36";
import { SystemRepository } from "../../domain/repositories/SystemRepository";
import { apiToFuture, FutureData } from "../api-futures";
import { getDateAsLocaleDateTimeString } from "./utils/DateTimeHelper";
import "moment-timezone";
import moment from "moment";

export class SystemD2Repository implements SystemRepository {
constructor(private api: D2Api) {}
Expand All @@ -12,18 +14,15 @@ export class SystemD2Repository implements SystemRepository {

//@ts-ignore
const lastAnalyticsTablePartitionSuccess = info.lastAnalyticsTablePartitionSuccess;

//If continious analytics is turned on, return it.
if (
info.lastAnalyticsTableSuccess &&
lastAnalyticsTablePartitionSuccess &&
new Date(lastAnalyticsTablePartitionSuccess) >
new Date(info.lastAnalyticsTableSuccess)
) {
return getDateAsLocaleDateTimeString(lastAnalyticsTablePartitionSuccess);
}
//Else, return the lastAnalyticsTableSuccess time
else if (info.lastAnalyticsTableSuccess) {
return getDateAsLocaleDateTimeString(info.lastAnalyticsTableSuccess.toISOString());
if (lastAnalyticsTablePartitionSuccess) {
const lastAnalyticsTablePartitionSuccessUTCString = moment
.tz(lastAnalyticsTablePartitionSuccess, info.serverTimeZoneId)
.utc()
.toString();

return getDateAsLocaleDateTimeString(lastAnalyticsTablePartitionSuccessUTCString);
} else {
return "Unable to fetch last analytics runtime";
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/repositories/utils/DateTimeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function getDateAsMonthYearString(date: Date): string {

export function getDateAsLocaleDateTimeString(date: string): string {
try {
return new Date(`${date}Z`).toString();
return moment(date).local().toDate().toString();
} catch (e) {
console.debug(e);
return "";
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8788,6 +8788,13 @@ moment-timezone@^0.5.31:
dependencies:
moment "^2.29.4"

moment-timezone@^0.5.46:
version "0.5.46"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.46.tgz#a21aa6392b3c6b3ed916cd5e95858a28d893704a"
integrity sha512-ZXm9b36esbe7OmdABqIWJuBBiLLwAjrN7CE+7sYdCCx82Nabt1wHDj8TVseS59QIlfFPbOoiBPm6ca9BioG4hw==
dependencies:
moment "^2.29.4"

[email protected]:
version "2.22.2"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66"
Expand Down

0 comments on commit ba2f3f2

Please sign in to comment.