Skip to content

Conversation

@victorboissiere
Copy link

I've enhanced the /api/status endpoint to support time range queries. Here's what was changed:

Current behavior was: Uptime calculated from start of current day to now (or specified timestamp).

Enhanced functionality:

  1. New parameters:
    - start_date: Start date in YYYY-MM-DD format
    - end_date: End date in YYYY-MM-DD format
  2. Usage examples:
    - GET /api/status?tag=your-monitor&start_date=2025-07-01&end_date=2025-07-31 - July uptime
    - GET /api/status?tag=your-monitor&start_date=2025-07-01 - From July 1st to now
    - GET /api/status?tag=your-monitor&end_date=2025-07-31 - July 31st (full day)
    - GET /api/status?tag=your-monitor - Current day (existing behavior)
  3. Enhanced response includes:
    - time_range.start: Start timestamp
    - time_range.end: End timestamp
    - Original fields: status, uptime, last_updated_at
  4. Error handling:
    - Invalid date formats
    - Start date after end date
    - No data for time range

The uptime calculation now works across any specified date range, giving you exactly what you requested - the ability to query uptime between
specific dates like July 1-31.

}
let start = GetDayStartTimestampUTC(now);

let start, end;
Copy link
Owner

Choose a reason for hiding this comment

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

start and end change to UTC, rest every api we use UTC

// Handle date range parameters
if (startDate && endDate) {
// Parse start_date and end_date (expecting YYYY-MM-DD format)
try {
Copy link
Owner

Choose a reason for hiding this comment

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

do not need try catch here if you handle it

let start, end;

// Handle date range parameters
if (startDate && endDate) {
Copy link
Owner

Choose a reason for hiding this comment

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

this code block could be simplified

handle error conditions and return as soon as possible in code, less if else

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