Skip to content

Conversation

@rogin
Copy link
Contributor

@rogin rogin commented Jul 3, 2025

Adds a checkbox to the Messages Browser and Events Browser which toggles the time format of the time input fields between HH:mm and hh:mm aa. On form load and on search reset, it defaults to 24hr notation.

I used most of the previous PR, but I changed the listener to one that responds to JCheckbox.setSelected(bool). Changes to the .form files were also included, but those may be completely unused.

Related
Previous PR - nextgenhealthcare/connect#5989
Summary table in #121

Signed-off-by: Richard Ogin <rogin@users.noreply.github.com>
@mgaffigan
Copy link
Contributor

Can this respect the OS preference instead? It looks like Java provides access to the user's preferred 12/24 time format via java.locale.providers=HOST for Windows and Mac on Java 11+.

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;

public class Main {
    public static void main(String[] args) {
        System.setProperty("java.locale.providers", "HOST");
        System.out.println(LocalTime.now().format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)));
    }
}

Prints 17:44 on Windows with 24-hour time set in Control Panel on Java 17.

@rogin
Copy link
Contributor Author

rogin commented Jul 27, 2025

Can this respect the OS preference instead? It looks like Java provides access to the user's preferred 12/24 time format via java.locale.providers=HOST for Windows and Mac on Java 11+.

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;

public class Main {
    public static void main(String[] args) {
        System.setProperty("java.locale.providers", "HOST");
        System.out.println(LocalTime.now().format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)));
    }
}

Prints 17:44 on Windows with 24-hour time set in Control Panel on Java 17.

I like the idea. Your link omits linux compatibility in Oracle's v11, so perhaps linux guys can check their systems. If good, I could add a new slot in Settings>Administrator>User Preferences, with an option like "Use 24 hour notation for search criteria" with Yes, No, Use system default. I'd model the logic of reading and storing the boolean like used for "Import code template libraries with channels".

@rogin
Copy link
Contributor Author

rogin commented Jul 28, 2025

Not bad
add-to-settings

Copy link
Member

@tonygermano tonygermano left a comment

Choose a reason for hiding this comment

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

I like having it configurable as a user preference. I'm not sure how useful it would be to pull from system preferences, because all of my desktop clocks are set to 12-hour format for display, but I would certainly rather use 24-hour format for search parameters instead of needing to add AM/PM. Search results already display in 24-hour format, and that is not configurable.

I know with user preferences they can either be saved in the database (which would follow the user to multiple devices when logging into the same server) or to the local machine, which won't follow the user if they log in on multiple devices, but should work across multiple server instances when logging in from the same device.

I think my preference would be to make it a local user preference that would default to 24-hour when not set. I think that follows the spirit of the original PR.

I'm not sure what the other implications are for forcing the locale provider to HOST. According to https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/spi/LocaleServiceProvider.html, that property is supposed to set the user's preferred lookup order. HOST is not always available in all runtime environments, nor is it even present in the default order of CLDR,COMPAT.

@mgaffigan
Copy link
Contributor

mgaffigan commented Jul 30, 2025

I think the way @rogin has done it is on point. Use the system preference by default, allow it to be overridden. We're specifically talking about a UI aspect - not a server or backend thing where there's a single right answer.

Respecting the user's system preferences is a UX best practice. People can be peeved when you do not (especially the "dark mode is the one true mode" crowd). Font size, contrast, motion preferences, dates/number/money formatting, theme/dark/light mode are all available from the system on Windows/Mac/Android/Web.

@jonbartels jonbartels added this to the Next Release milestone Jul 31, 2025
@tonygermano
Copy link
Member

I'll try to bullet-point my previous comment. I'm not disagreeing with you about respecting user preferences.

  1. The system property java.locale.providers is a user preference. The proposed change would ignore the user setting that property and override it.
  2. I am unsure of the consequences of changing the default value from CLDR,COMPAT to HOST and I think that needs to be evaluated outside the context of this PR only.
  3. 24-hour should likely be the default regardless of the setting for the user's system clock because
    1. The search results are already in 24-hour format, and that is not configurable. The search parameter should match.
    2. 24-hour format is easier to type
    3. Many people don't change their system clock to 24-hour format, nor do they have a desire to. Searching a log and glancing at a clock are not the same use case.
  4. By storing it as a local preference, if the user sets the value to 12-hour one time, it should apply to all servers they access from that client device.

When it comes to the release notes I think this would capture the two choices we are discussing:

  1. When searching messages or events, the time selection now defaults to 24-hour format. If you prefer to retain the previous behavior go to Settings-> User Preference and change the "Message searches use 24-hour format" value to "No."
  2. When searching messages or events, the time selection now supports 24-hour format and will match the settings of your system clock by default. If you prefer to change this behavior to always use 12-hour or 24-hour format, go to Settings-> User Preference and change the "Message searches use 24-hour format" value to "Yes" or "No" accordingly.

I think the first option is cleaner and will require fewer people to actually need to go in and change the setting.

@mgaffigan
Copy link
Contributor

@tonygermano, This is not my issue - so I'm not pushing here. I stand by the comment re: best practice, but will not oppose regardless of outcome of this PR.

@tonygermano tonygermano added the enhancement New feature or request label Aug 1, 2025
@rogin
Copy link
Contributor Author

rogin commented Aug 7, 2025

I agree with Tony's first option. I'll update the code.

@kryskool
Copy link

Hi

In France we use the 24H date formatting, and when i go to View Message, i see the date in column is in the 24h format
and on the earch part, we have the 12h format, the information is therefore inconsistent

mstsc_rkQg6hQ4XH

I think the date column is the result come from the database, that's why we have the inforamtion in the 24h format

Regards,

@UZ-Brussel-VUB
Copy link

UZ-Brussel-VUB commented Aug 26, 2025

Not only in France, Belgium (And I guess the rest of europe too) use the 24h notation too.
I did the same, without the user preferences. Maybe the UI stuff can be added already and later on the user preferences?

Copy link

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

This PR adds a "24 hour" checkbox to the Messages Browser and Events Browser that allows users to toggle between 24-hour (HH:mm) and 12-hour (hh:mm aa) time formats. The feature defaults to 24-hour notation on form load and when search criteria is reset.

Key Changes:

  • Added setFormatter() method to MirthTimePicker to allow dynamic format changes
  • Implemented hourNotation24 checkbox in both MessageBrowser and EventBrowser with itemStateChanged listeners
  • Updated time format handling in getCalendar() methods to respect the user's notation preference

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
client/src/com/mirth/connect/client/ui/components/MirthTimePicker.java Refactored initialization to extract formatter setup into a new public setFormatter() method that can be called dynamically
client/src/com/mirth/connect/client/ui/browsers/message/MessageBrowser.java Added hourNotation24 checkbox with UI layout, initialization logic, reset handling, and event listener to toggle time picker formats
client/src/com/mirth/connect/client/ui/browsers/message/MessageBrowser.form Updated NetBeans form definition to include the new checkbox component and layout adjustments
client/src/com/mirth/connect/client/ui/browsers/event/EventBrowser.java Added hourNotation24 checkbox with UI layout, initialization logic, reset handling, and event listener to toggle time picker formats
client/src/com/mirth/connect/client/ui/browsers/event/EventBrowser.form Updated NetBeans form definition to include the new checkbox component and layout adjustments

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

statusBoxTransformed = new com.mirth.connect.client.ui.components.MirthCheckBox();
mirthTimePicker1 = new com.mirth.connect.client.ui.components.MirthTimePicker();
mirthTimePicker1 = new com.mirth.connect.client.ui.components.MirthTimePicker((use24hourNotation ? "HH:mm" : "hh:mm aa"), Calendar.MINUTE);
hourNotation24 = new com.mirth.connect.client.ui.components.MirthCheckBox();
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The hourNotation24 checkbox should be initialized with setSelected(true) in initComponents() to be consistent with the default use24hourNotation = true value and with EventBrowser's implementation. Without this, the checkbox will be unchecked by default even though 24-hour notation is used.

Suggestion: Add hourNotation24.setSelected(true); after this line, similar to EventBrowser line 977.

Suggested change
hourNotation24 = new com.mirth.connect.client.ui.components.MirthCheckBox();
hourNotation24 = new com.mirth.connect.client.ui.components.MirthCheckBox();
hourNotation24.setSelected(true);

Copilot uses AI. Check for mistakes.
<Property name="text" type="java.lang.String" value="24 hour"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="11" style="0"/>
</Property>
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The hourNotation24 checkbox is missing a toolTipText property in the .form file. The Java code sets it at line 2928, but it should also be defined here for consistency with the design pattern used for other checkboxes in the form.

Suggestion: Add a toolTipText property with value "Use 24 hour notation" to match the Java code.

Suggested change
</Property>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Use 24 hour notation"/>

Copilot uses AI. Check for mistakes.
<Property name="text" type="java.lang.String" value="24 hour"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="11" style="0"/>
</Property>
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The hourNotation24 checkbox is missing a toolTipText property in the .form file. The Java code sets it at line 980, but it should also be defined here for consistency with the design pattern used for other checkboxes in the form.

Suggestion: Add a toolTipText property with value "Use 24 hour notation" to match the Java code.

Suggested change
</Property>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Use 24 hour notation"/>

Copilot uses AI. Check for mistakes.
DefaultFormatterFactory factory = (DefaultFormatterFactory) tf.getFormatterFactory();
formatter = (DateFormatter) factory.getDefaultFormatter();
formatter.setFormat(dateFormat);
fireStateChanged();
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The setFormatter() method calls fireStateChanged() which will trigger change listeners. When toggling the 24-hour checkbox, this causes two fireStateChanged() calls (one for each time picker), which may trigger unnecessary UI updates or save state changes if listeners are attached.

Consider whether fireStateChanged() is necessary in this method, or if it should only be called when the value actually changes (not just the format).

Suggested change
fireStateChanged();

Copilot uses AI. Check for mistakes.
hourNotation24.setText("24 hour");
hourNotation24.setToolTipText("Use 24 hour notation");
hourNotation24.setFont(new java.awt.Font("Lucida Grande", 0, 11)); // NOI18N
hourNotation24.addItemListener(new java.awt.event.ItemListener() {
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

This method overrides ItemListener.itemStateChanged; it is advisable to add an Override annotation.

Suggested change
hourNotation24.addItemListener(new java.awt.event.ItemListener() {
hourNotation24.addItemListener(new java.awt.event.ItemListener() {
@Override

Copilot uses AI. Check for mistakes.
hourNotation24.setText("24 hour");
hourNotation24.setToolTipText("Use 24 hour notation");
hourNotation24.setFont(new java.awt.Font("Lucida Grande", 0, 11)); // NOI18N
hourNotation24.addItemListener(new java.awt.event.ItemListener() {
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

This method overrides ItemListener.itemStateChanged; it is advisable to add an Override annotation.

Suggested change
hourNotation24.addItemListener(new java.awt.event.ItemListener() {
hourNotation24.addItemListener(new java.awt.event.ItemListener() {
@Override

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants