Date Filter Shows Seconds Inconsistently After Editing #165

Closed
opened 2026-04-05 16:18:59 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @TomTom-Labs on 1/14/2026

Summary

In the Monitor Log Filters, the "Monitor at" date range filter has two datetime input fields. When the user starts editing the first date field, the second date field unexpectedly starts displaying seconds (:00), even though both fields initially showed only hours and minutes.


Steps to Reproduce

  1. Navigate to Monitor → View → Logs page
  2. Observe the "Monitor at" filter with two date/time input fields (From and To)
  3. Note that both fields display time as HH:MM (e.g., 12:30)
  4. Click on the first date input field and change any value (date or time)
  5. Observe the second date input field

Expected Behavior

Both date input fields should maintain consistent formatting. If they initially show HH:MM, they should continue showing HH:MM after either field is edited.


Actual Behavior

After editing the first date field, the second date field changes its display format from HH:MM to HH:MM:SS (e.g., 12:30 becomes 12:30:00), even though the user did not interact with it.

Image Image

Notes

Root Cause Analysis

The issue involves two files:

  1. StartAndEndDate.tsx (Common/UI/Components/Date/StartAndEndDate.tsx) - Contains the two date input fields ("From:" and "To:"). When either field is edited, the component's state updates and triggers a re-render of both inputs.

  2. Date.ts (Common/Types/Date.ts, lines 443-459) - The toDateTimeLocalString() method always formats dates with seconds included:

    return YYYY + "-" + MM + "-" + DD + "T" + HH + ":" + II + ":" + SS;
    

Why this happens:

  • The HTML datetime-local input type only displays seconds when the value string explicitly contains them
  • Initially, the date values may not have explicit seconds in their string representation
  • When the first field is edited, the value goes through Date object conversion and back to string
  • The toDateTimeLocalString() method outputs the value with :SS suffix
  • On re-render, both fields receive values with explicit seconds, causing the browser to display them

Create a new method toDateTimeLocalStringWithoutSeconds() in Date.ts that excludes seconds from the output:

public static toDateTimeLocalStringWithoutSeconds(date: Date): string {
  date = this.fromString(date);

  type TenFunction = (i: number) => string;

  const ten: TenFunction = (i: number): string => {
      return (i < 10 ? "0" : "") + i;
    },
    YYYY: number = date.getFullYear(),
    MM: string = ten(date.getMonth() + 1),
    DD: string = ten(date.getDate()),
    HH: string = ten(date.getHours()),
    II: string = ten(date.getMinutes());

  return YYYY + "-" + MM + "-" + DD + "T" + HH + ":" + II;
}

Then update Input.tsx (lines 79 and 97) to use the new method instead of toDateTimeLocalString().

Why not modify the existing method:

The existing toDateTimeLocalString() method is also used by TaskLogger.ts for logging timestamps, where second-level precision is valuable. Creating a separate method preserves backward compatibility and allows each use case to have the appropriate level of precision.

*Originally created by @TomTom-Labs on 1/14/2026* ### Summary In the Monitor Log Filters, the "Monitor at" date range filter has two datetime input fields. When the user starts editing the first date field, the second date field unexpectedly starts displaying seconds (`:00`), even though both fields initially showed only hours and minutes. --- ### Steps to Reproduce 1. Navigate to **Monitor → View → Logs** page 2. Observe the "Monitor at" filter with two date/time input fields (From and To) 3. Note that both fields display time as `HH:MM` (e.g., `12:30`) 4. Click on the **first** date input field and change any value (date or time) 5. Observe the **second** date input field --- ### Expected Behavior Both date input fields should maintain consistent formatting. If they initially show `HH:MM`, they should continue showing `HH:MM` after either field is edited. --- ### Actual Behavior After editing the first date field, the second date field changes its display format from `HH:MM` to `HH:MM:SS` (e.g., `12:30` becomes `12:30:00`), even though the user did not interact with it. <img width="1233" height="307" alt="Image" src="https://github.com/user-attachments/assets/34da0467-3f42-4afa-956f-5aee169873e6" /> <img width="1295" height="495" alt="Image" src="https://github.com/user-attachments/assets/4b1ce77c-443f-4700-9867-dc3782d9c2e2" /> --- ### Notes #### Root Cause Analysis The issue involves two files: 1. **StartAndEndDate.tsx** (`Common/UI/Components/Date/StartAndEndDate.tsx`) - Contains the two date input fields ("From:" and "To:"). When either field is edited, the component's state updates and triggers a re-render of both inputs. 2. **Date.ts** (`Common/Types/Date.ts`, lines 443-459) - The `toDateTimeLocalString()` method always formats dates with seconds included: ```typescript return YYYY + "-" + MM + "-" + DD + "T" + HH + ":" + II + ":" + SS; ``` **Why this happens:** - The HTML `datetime-local` input type only displays seconds when the value string explicitly contains them - Initially, the date values may not have explicit seconds in their string representation - When the first field is edited, the value goes through `Date` object conversion and back to string - The `toDateTimeLocalString()` method outputs the value with `:SS` suffix - On re-render, both fields receive values with explicit seconds, causing the browser to display them --- ### Recommended Solution Create a new method `toDateTimeLocalStringWithoutSeconds()` in `Date.ts` that excludes seconds from the output: ```typescript public static toDateTimeLocalStringWithoutSeconds(date: Date): string { date = this.fromString(date); type TenFunction = (i: number) => string; const ten: TenFunction = (i: number): string => { return (i < 10 ? "0" : "") + i; }, YYYY: number = date.getFullYear(), MM: string = ten(date.getMonth() + 1), DD: string = ten(date.getDate()), HH: string = ten(date.getHours()), II: string = ten(date.getMinutes()); return YYYY + "-" + MM + "-" + DD + "T" + HH + ":" + II; } ``` Then update `Input.tsx` (lines 79 and 97) to use the new method instead of `toDateTimeLocalString()`. **Why not modify the existing method:** The existing `toDateTimeLocalString()` method is also used by `TaskLogger.ts` for logging timestamps, where second-level precision is valuable. Creating a separate method preserves backward compatibility and allows each use case to have the appropriate level of precision.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/oneuptime#165