-
Notifications
You must be signed in to change notification settings - Fork 125
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
Conversation
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
There was a problem hiding this 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
/** | ||
* @return the value of the Global Propriety Handle Timezones | ||
*/ | ||
public boolean handleTimeZones(){ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.. :) )
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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()" ?
There was a problem hiding this comment.
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().
<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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is in platform 2.4 https://github.com/openmrs/openmrs-core/blob/2.4.0/pom.xml#L574-L578
There was a problem hiding this comment.
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.
Thanks @mks-d for the review request... may take me a couple days to get to it, but I will review. |
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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)); | |||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(){ |
There was a problem hiding this comment.
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.. :) )
@mogoodrich the |
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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
I think 'handleTimeZonesOnClientSide' it's a good name |
Change function to format date to use fromISO8601
@@ -150,6 +151,7 @@ public void testFormattingADateWithNoTime() throws Exception { | |||
@Test | |||
public void testFormattingADateWithATime() throws Exception { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
Ticket:
https://issues.openmrs.org/browse/HTML-755
What I have done:
UiUtils
methods for time zones support and dates formatting.String
toDate
.