Skip to content

fix: add challenge completion timestamp #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/util/DateUtil.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";

import timezone from "dayjs/plugin/timezone";
import advanced from "dayjs/plugin/advancedFormat";

dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(advanced);

export const IFX_TIMEZONE = "America/New_York";
export const dateFormatIfx = "YYYY-MM-DD HH:mm:ss";
export const IFX_DATE_FORMAT = "YYYY-MM-DD HH:mm:ss";

class DateUtil {
public formatDateForIfx(date: string): string | undefined {
public formatDateForIfx(date: string, format: string = IFX_DATE_FORMAT): string | undefined {
const parsedDate = dayjs(date);
return parsedDate.isValid()
? parsedDate.tz(IFX_TIMEZONE).format(dateFormatIfx)
: undefined;
return parsedDate.isValid() ? parsedDate.tz(IFX_TIMEZONE).format(format) : undefined;
}

public isValidDate(date: string) {
Expand Down
4 changes: 4 additions & 0 deletions src/util/LegacyMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from "@topcoder-framework/domain-acl";
import { getRequest } from "../api/v5Api";
import m2mToken from "../helpers/MachineToMachineToken";
import DateUtil from "./DateUtil";

class LegacyMapper {
// To be used on challenge:update calls that change state from New -> Draft
Expand Down Expand Up @@ -243,6 +244,9 @@ class LegacyMapper {
if (input.billing?.billingAccountId != null) {
projectInfo[32] = input.billing?.billingAccountId!.toString();
}
if (input.status === ChallengeStatuses.Completed) {
projectInfo[21] = DateUtil.formatDateForIfx(new Date().toISOString(), "MM.DD.YYYY HH:mm z")!; // project_info 21 is Completion Timestamp; and it has a different date format
}

const map = {
...projectInfo,
Expand Down