Skip to content

HOTFIX-FA-1393#954

Merged
ramirezmorac2 merged 1 commit intodevelopfrom
HOTFIX-FA-1393
Mar 23, 2026
Merged

HOTFIX-FA-1393#954
ramirezmorac2 merged 1 commit intodevelopfrom
HOTFIX-FA-1393

Conversation

@ramirezmorac2
Copy link
Copy Markdown
Collaborator

Add utility functions for local start and end of day Unix timestamp conversion in getUserActivityLogs

JIRA Ticket

PROJ-XXX

Description

[Describe your changes here]

Checklist

  • Code review requested
  • Tests completed
  • Documentation updated

Copilot AI review requested due to automatic review settings March 23, 2026 22:22
@ramirezmorac2 ramirezmorac2 merged commit 917ce4d into develop Mar 23, 2026
2 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds frontend-side utilities to convert YYYY-MM-DD date strings into local start/end-of-day Unix timestamps, and uses those when calling the platform-admin user activity logs endpoint.

Changes:

  • Introduces toLocalStartOfDayUnixTimestamp and toLocalEndOfDayUnixTimestamp helpers in the frontend API layer.
  • Updates getUserActivityLogs to use those helpers instead of UTC (...Z) timestamp construction.

Comment thread frontend/src/api/api.ts
Comment on lines +2358 to +2364
function toLocalStartOfDayUnixTimestamp(dateString: string): number {
const [year, month, day] = dateString.split("-").map(Number);
return Math.floor(new Date(year, month - 1, day, 0, 0, 0).getTime() / 1000);
}

function toLocalEndOfDayUnixTimestamp(dateString: string): number {
const [year, month, day] = dateString.split("-").map(Number);
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toLocalStartOfDayUnixTimestamp / toLocalEndOfDayUnixTimestamp will return NaN if dateString isn’t exactly a YYYY-MM-DD value (e.g., unexpected format, partial input). That would serialize as start_date=NaN/end_date=NaN, and the backend currently does int(start_date) which will raise and return a 500. Consider validating/parsing defensively (e.g., strict regex + component range check) and either throw a client-side error or skip appending the query param when parsing fails.

Suggested change
function toLocalStartOfDayUnixTimestamp(dateString: string): number {
const [year, month, day] = dateString.split("-").map(Number);
return Math.floor(new Date(year, month - 1, day, 0, 0, 0).getTime() / 1000);
}
function toLocalEndOfDayUnixTimestamp(dateString: string): number {
const [year, month, day] = dateString.split("-").map(Number);
function parseYmdDate(dateString: string): { year: number; month: number; day: number } {
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dateString);
if (!match) {
throw new Error('Invalid date format. Expected YYYY-MM-DD.');
}
const year = Number(match[1]);
const month = Number(match[2]);
const day = Number(match[3]);
if (!Number.isFinite(year) || !Number.isFinite(month) || !Number.isFinite(day)) {
throw new Error('Invalid date components. Expected numeric year, month, and day.');
}
if (month < 1 || month > 12) {
throw new Error('Invalid month in date. Expected 01-12.');
}
const daysInMonth = new Date(year, month, 0).getDate();
if (day < 1 || day > daysInMonth) {
throw new Error('Invalid day in date for the given month/year.');
}
return { year, month, day };
}
function toLocalStartOfDayUnixTimestamp(dateString: string): number {
const { year, month, day } = parseYmdDate(dateString);
return Math.floor(new Date(year, month - 1, day, 0, 0, 0).getTime() / 1000);
}
function toLocalEndOfDayUnixTimestamp(dateString: string): number {
const { year, month, day } = parseYmdDate(dateString);

Copilot uses AI. Check for mistakes.
Comment thread frontend/src/api/api.ts
Comment on lines 2375 to 2381
if (startDate) {
const startTimestamp = Math.floor(new Date(startDate + "T00:00:00Z").getTime() / 1000);
const startTimestamp = toLocalStartOfDayUnixTimestamp(startDate);
params.append("start_date", startTimestamp.toString());
}
if (endDate) {
const endTimestamp = Math.floor(new Date(endDate + "T23:59:59Z").getTime() / 1000);
const endTimestamp = toLocalEndOfDayUnixTimestamp(endDate);
params.append("end_date", endTimestamp.toString());
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters the request query parameters by converting startDate/endDate to local-day Unix timestamps. There are Jest tests for other API functions under frontend/src/api/tests/; adding a focused test for getUserActivityLogs would help prevent regressions (e.g., verify the generated URL/query params for a fixed process.env.TZ, and that invalid date strings don’t send NaN).

Copilot uses AI. Check for mistakes.
ramirezmorac2 added a commit that referenced this pull request Mar 23, 2026
* FA-1378 Move share conversation feature from orchestrator to frontend, implementing direct export functionality with support for HTML and JSON formats. (#949)

* Fix download functionality in Gallery component to use SAS URL for file access and handle unauthorized sessions (#951)

* FA-1393 Fix end date timestamp calculation in getUserActivityLogs to include the entire day (#952)

* Add utility functions for local start and end of day Unix timestamp conversion in getUserActivityLogs (#954)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants