Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML-755: UIFR to expose time zones support API. #65

Closed
wants to merge 10 commits into from

Conversation

icrc-jfigueiredo
Copy link
Contributor

@icrc-jfigueiredo icrc-jfigueiredo commented Feb 26, 2021

Ticket:

https://issues.openmrs.org/browse/HTML-755

What I have done:

  • Added new GP to switch on/off support for time zones.
  • Added new UiUtils methods for time zones support and dates formatting.
  • Added new date parsers to parse from ISO 8601 String to Date.

icrc-jfigueiredo and others added 2 commits February 27, 2021 03:16
Add new GP handling timezones.
Add new functions on uiutils about timezone and date formats from UiFramework
Add new date parses to be able to:
    Parse from string with format ISO8601 to date
    Parse Date format to string with RFC3339 format
@mks-d mks-d changed the title HTML-755 Timezones, add new GP and update UiUtils with date formats HTML-755: UIFR to expose time zones support API. Mar 10, 2021
@mks-d mks-d requested review from mks-d and mogoodrich March 10, 2021 12:10
Copy link
Member

@mks-d mks-d left a comment

Choose a reason for hiding this comment

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

@icrc-jfigueiredo a couple of comments, and importantly we need to address failing tests: https://travis-ci.org/github/openmrs/openmrs-module-uiframework/builds/761266556#L2266-L2273

api/src/main/java/org/openmrs/util/TimeZoneUtil.java Outdated Show resolved Hide resolved
/**
* @return the value of the Global Propriety Handle Timezones
*/
public boolean handleTimeZones(){
Copy link
Member

Choose a reason for hiding this comment

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

@mogoodrich are you ok with this name?
Or perhaps hasTimeZonesSupport() or timeZonesSupport()?

Would be good to know early because this will be referred to in many modules.

@ibacher you're great at this kind of thing ;-) Your ideas would be more than welcome.

Copy link
Member

Choose a reason for hiding this comment

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

I know we've talked about this ad nauseum but I always forget the exact details... "handle" time zones feels a bit vague... I'd be in favor of something more specific... per my above comment are we says "never format timezones for display on the server side, force RFC3339 format" (not my suggestion for a GP.. :) )

Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like: sendDatetimeAsUTC? Not my favourite phrasing, but accurate.

Copy link
Member

Choose a reason for hiding this comment

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

That's decent @ibacher ....

@@ -42,6 +39,7 @@

private MessageSource messageSource;
private AdministrationService administrationService;
private UiUtils ui = new BasicUiUtils();
Copy link
Member

Choose a reason for hiding this comment

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

@mogoodrich is it ok to access UiUtils from here and in that way?
I would think that this was not the intent of this class, but maybe it's ok and since it works...

Copy link
Member

Choose a reason for hiding this comment

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

In general, I'm okay with it, but isn't a bit weird/recursive in this case, because the UiUtils has the formatter wired into it? ie the format method below is usually accessed via "uiUtils.format()" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can always remove that UiUtils and get the GP directly... Instead of using ui.handleTimeZones().

Comment on lines +64 to +73
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.joda</groupId>
<artifactId>joda-convert</artifactId>
<version>1.2</version>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

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

@icrc-jfigueiredo you sure you need this, Joda-Time is normally coming with Core.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could not found Joda-Time in Core, that is why I added it here.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are still using 2.3, once we update it to 2.4 I can remove it.

@mogoodrich
Copy link
Member

Thanks @mks-d for the review request... may take me a couple days to get to it, but I will review.

Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

Thanks @icrc-jfigueiredo @mks-d I added some initial thoughts... it still makes my head hurt, but this helps me understand things a little better. Are these all the changes we expect to make to the UI Framework module? It might make sense to get them all into the PR because that may make it easier to come up with a naming convention for the GP?

Right now that GP is only being used in one place, the "format" method. "Format" is intended generally used for formatting an element for display. And what we are kind of doing here, if the GP is set to "true", is saying "never format a date for display, keep it in RFC3339 format and let the client handle the formatting, so it can use it's own time zone" (again, not the right name for a GP, but hopefully will help us get closer to a better name... :) )

Hope that's helpful!

@@ -42,6 +39,7 @@

private MessageSource messageSource;
private AdministrationService administrationService;
private UiUtils ui = new BasicUiUtils();
Copy link
Member

Choose a reason for hiding this comment

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

In general, I'm okay with it, but isn't a bit weird/recursive in this case, because the UiUtils has the formatter wired into it? ie the format method below is usually accessed via "uiUtils.format()" ?

@@ -113,6 +119,9 @@ private boolean wholeNumber(Number n) {

private String format(Date d, Locale locale) {
DateFormat df;
if(ui.handleTimeZones()){
return (toRFC3339(d));
}
Copy link
Member

Choose a reason for hiding this comment

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

The "format" method is primarily about formatting something for display... are we saying when "handleTimeZones" is enabled we never want to format for display on the server side, but always render in RFC3339 format?

Copy link
Contributor Author

@icrc-jfigueiredo icrc-jfigueiredo Mar 15, 2021

Choose a reason for hiding this comment

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

Exactly that, because, if timezones are enabled, we always need to format on the client side, with client timezone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the UiUtils there and now we are getting the GP directly here

/**
* @return the value of the Global Propriety Handle Timezones
*/
public boolean handleTimeZones(){
Copy link
Member

Choose a reason for hiding this comment

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

I know we've talked about this ad nauseum but I always forget the exact details... "handle" time zones feels a bit vague... I'd be in favor of something more specific... per my above comment are we says "never format timezones for display on the server side, force RFC3339 format" (not my suggestion for a GP.. :) )

@icrc-jfigueiredo
Copy link
Contributor Author

@mogoodrich the public boolean handleTimeZones(){ it's not only for formatting dates, in the case of the UiFramework it is, but this will be used in other modules (coreApps, HFE-UI, Attachments ...) so they know we are using timezones (to know the GP value). Example here

@mogoodrich
Copy link
Member

mogoodrich commented Mar 15, 2021

@mogoodrich the public boolean handleTimeZones(){ it's not only for formatting dates, in the case of the UiFramework it is, but this will be used in other modules (coreApps, HFE-UI, Attachments ...) so they know we are using timezones (to know the GP value). Example here

Then maybe something like "handleTimeZonesOnClientSide" or "convertToClientTimeZone"? Not sure I love those either?

* @return The date formated as RFC 3339.
*/
public static String toRFC3339(Date date) {
return ISODateTimeFormat.dateTime().print(new DateTime(date.getTime(), UTC));
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this just treat the date as if it were a UTC date rather than a server time-zone specific date?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it convert to UTC and use the ISO8601 format, that in this case its the same as RFC3339, which is what client side is expecting.

@icrc-jfigueiredo
Copy link
Contributor Author

@mogoodrich the public boolean handleTimeZones(){ it's not only for formatting dates, in the case of the UiFramework it is, but this will be used in other modules (coreApps, HFE-UI, Attachments ...) so they know we are using timezones (to know the GP value). Example here

Then maybe something like "handleTimeZonesOnClientSide" or "convertToClientTimeZone"? Not sure I love those either?

I think 'handleTimeZonesOnClientSide' it's a good name

@mks-d mks-d requested a review from dkayiwa March 16, 2021 10:39
@@ -150,6 +151,7 @@ public void testFormattingADateWithNoTime() throws Exception {
@Test
public void testFormattingADateWithATime() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about the test method name, what is this test about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is not something we introduce, its an old test, that see if the date is well formatted by FormatterImpl.java

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough 😊

* @return The Date object.
* @Throws IllegalArgumentException – if string parameter does not conform to lexical value space
*/
public static Date fromISO8601(String s) throws
Copy link
Member

Choose a reason for hiding this comment

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

Do you mind using a more descriptive parameter name than s?

Copy link
Contributor Author

@icrc-jfigueiredo icrc-jfigueiredo Mar 17, 2021

Choose a reason for hiding this comment

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

I change it to public static Date fromISO8601(String isoDateString) throws here, is this ok to you?

Copy link
Member

Choose a reason for hiding this comment

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

Looks good.

@@ -586,4 +586,30 @@ public Locale getLocale() {
public void setLocale(Locale locale) {
this.locale = locale;
}

/**
Copy link
Member

Choose a reason for hiding this comment

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

It would be great to add the method description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but that is something that was create in 2013, I added a little description here

Copy link
Member

@dkayiwa dkayiwa Mar 17, 2021

Choose a reason for hiding this comment

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

oh, ok.

@@ -113,6 +114,10 @@ private boolean wholeNumber(Number n) {

private String format(Date d, Locale locale) {
DateFormat df;
if(Boolean.parseBoolean(
Copy link
Member

@dkayiwa dkayiwa Mar 16, 2021

Choose a reason for hiding this comment

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

How about using BooleanUtils.toBoolean() to also accept on, yes, t, y as true values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes a lot of sense, I changed it to use BooleanUtils.toBoolean() as you can see here and here.

@icrc-jfigueiredo
Copy link
Contributor Author

Hello, I created a NEW PR for UiFramework, with a User Propriety to save the client timezone, so the server can send the date formatted on client timezone, instead of doing that on the client side.

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.

6 participants