Conversation
…onversion in getUserActivityLogs
There was a problem hiding this comment.
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
toLocalStartOfDayUnixTimestampandtoLocalEndOfDayUnixTimestamphelpers in the frontend API layer. - Updates
getUserActivityLogsto use those helpers instead of UTC (...Z) timestamp construction.
| 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); |
There was a problem hiding this comment.
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.
| 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); |
| 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()); |
There was a problem hiding this comment.
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).
* 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)
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