Skip to content

Commit

Permalink
SAK-40226 can now use datepicker in your preferred time zone (sakaipr…
Browse files Browse the repository at this point in the history
…oject#7567)

* SAK-40226 now able to use localDatePicker and set main dates in your preferred time zone

* SAK-40226 also handle extended time

* SAK-40226 better log debug
  • Loading branch information
ottenhoff authored Nov 22, 2019
1 parent 4798820 commit 80a7128
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
Expand Down Expand Up @@ -143,26 +146,42 @@ public String getDateTimeWithTimezoneConversion(Date dateToConvert) {
}
return dt.toString(fmt) + " " + dt.toString(fmtTime);
}

/*
* SAM-2323: the jquery-ui datepicker provides a hidden field with ISO-8601 date/time
* This method will convert that date string into a Java Date
* User could be in a different timezone and modifying dates in the date picker.
* We need to take the user date and convert back to server time zone for storage in database.
*/
public Date parseISO8601String(String dateString) {
if (StringUtils.isBlank(dateString)) {
return null;
}

try {
// Hidden field from the datepicker will look like: 2015-02-19T02:25:00-06:00
DateTime dt = dtf.parseDateTime(dateString);
return dt.toDate();
} catch (Exception e) {
log.error("parseISO8601String could not parse: " + dateString);
}

return null;
public Date parseISO8601String(final String dateString) {
if (StringUtils.isBlank(dateString)) {
return null;
}

try {
// Hidden field from the datepicker will look like: 2015-02-19T02:25:00-06:00
// But that timezone offset is the client browser time zone offset (not necessarily their preferred time zone).
// So bring in the time as LocalDateTime and then do the zone manipulation later.
// 2015-02-19T02:25:00 = 19 characters
final String localDateString = StringUtils.left(dateString, 19);
LocalDateTime ldt = LocalDateTime.parse(localDateString);
log.debug("parseISO8601String: string={}, localdate={}", dateString, ldt.toString());

if (ldt != null && m_client_timezone != null && m_server_timezone != null && !m_client_timezone.hasSameRules(m_server_timezone)) {
ZonedDateTime zdt = ldt.atZone(m_client_timezone.toZoneId());
log.debug("parseISO8601String: original={}, zoned={}", dateString, zdt.toString());
return Date.from(zdt.toInstant());
}
else if (ldt != null && m_server_timezone != null) {
ZonedDateTime zdt = ldt.atZone(m_server_timezone.toZoneId());
return Date.from(zdt.toInstant());
}
else if (ldt != null) {
return Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
}
} catch (Exception e) {
log.error("parseISO8601String could not parse: {}", dateString);
}

return null;
}



}
10 changes: 5 additions & 5 deletions samigo/samigo-app/src/webapp/jsf/author/authorSettings.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -112,39 +112,39 @@
useTime: 1,
parseFormat: 'YYYY-MM-DD HH:mm:ss',
allowEmptyDate: false,
val: '<h:outputText value="#{assessmentSettings.startDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/></h:outputText>',
val: '<h:outputText value="#{assessmentSettings.startDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{author.userTimeZone}"/></h:outputText>',
ashidden: { iso8601: 'startDateISO8601' }
});
localDatePicker({
input: '#assessmentSettingsAction\\:endDate',
useTime: 1,
parseFormat: 'YYYY-MM-DD HH:mm:ss',
allowEmptyDate: true,
val: '<h:outputText value="#{assessmentSettings.dueDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/></h:outputText>',
val: '<h:outputText value="#{assessmentSettings.dueDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{author.userTimeZone}"/></h:outputText>',
ashidden: { iso8601: 'endDateISO8601' }
});
localDatePicker({
input: '#assessmentSettingsAction\\:retractDate',
useTime: 1,
parseFormat: 'YYYY-MM-DD HH:mm:ss',
allowEmptyDate: true,
val: '<h:outputText value="#{assessmentSettings.retractDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/></h:outputText>',
val: '<h:outputText value="#{assessmentSettings.retractDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{author.userTimeZone}"/></h:outputText>',
ashidden: { iso8601: 'retractDateISO8601' }
});
localDatePicker({
input: '#assessmentSettingsAction\\:feedbackDate',
useTime: 1,
parseFormat: 'YYYY-MM-DD HH:mm:ss',
allowEmptyDate: true,
val: '<h:outputText value="#{assessmentSettings.feedbackDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/></h:outputText>',
val: '<h:outputText value="#{assessmentSettings.feedbackDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{author.userTimeZone}"/></h:outputText>',
ashidden: { iso8601: 'feedbackDateISO8601' }
});
localDatePicker({
input: '#assessmentSettingsAction\\:feedbackEndDate',
useTime: 1,
parseFormat: 'YYYY-MM-DD HH:mm:ss',
allowEmptyDate: true,
val: '<h:outputText value="#{assessmentSettings.feedbackEndDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/></h:outputText>',
val: '<h:outputText value="#{assessmentSettings.feedbackEndDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{author.userTimeZone}"/></h:outputText>',
ashidden: { iso8601: 'feedbackEndDateISO8601' }
});
localDatePicker({
Expand Down
6 changes: 3 additions & 3 deletions samigo/samigo-app/src/webapp/jsf/author/inc/extendedTime.jspf
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,23 @@
<h:outputText value="#{assessmentSettingsMessages.header_extendedTime_start_date}" />
</f:facet>
<h:outputText id="extendedTimeStartDate" value="#{entry.startDate}">
<f:convertDateTime pattern="#{generalMessages.output_date_no_sec}"/>
<f:convertDateTime dateStyle="medium" timeStyle="short" timeZone="#{author.userTimeZone}" />
</h:outputText>
</h:column>
<h:column headerClass="extendedTime-due">
<f:facet name="header">
<h:outputText value="#{assessmentSettingsMessages.header_extendedTime_due_date}" />
</f:facet>
<h:outputText id="extendedTimeEndDate" value="#{entry.dueDate}">
<f:convertDateTime pattern="#{generalMessages.output_date_no_sec}"/>
<f:convertDateTime dateStyle="medium" timeStyle="short" timeZone="#{author.userTimeZone}" />
</h:outputText>
</h:column>
<h:column headerClass="extendedTime-retract">
<f:facet name="header">
<h:outputText value="#{assessmentSettingsMessages.header_extendedTime_retract_date}" />
</f:facet>
<h:outputText id="extendedTimeRetractDate" value="#{entry.retractDate}">
<f:convertDateTime pattern="#{generalMessages.output_date_no_sec}"/>
<f:convertDateTime dateStyle="medium" timeStyle="short" timeZone="#{author.userTimeZone}" />
</h:outputText>
</h:column>
<h:column headerClass="extendedTime-hours">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,23 @@
<h:outputText value="#{assessmentSettingsMessages.header_extendedTime_start_date}" />
</f:facet>
<h:outputText id="extendedTimeStartDate" value="#{entry.startDate}">
<f:convertDateTime pattern="#{generalMessages.output_date_no_sec}"/>
<f:convertDateTime dateStyle="medium" timeStyle="short" timeZone="#{author.userTimeZone}" />
</h:outputText>
</h:column>
<h:column headerClass="extendedTime-due">
<f:facet name="header">
<h:outputText value="#{assessmentSettingsMessages.header_extendedTime_due_date}" />
</f:facet>
<h:outputText id="extendedTimeEndDate" value="#{entry.dueDate}">
<f:convertDateTime pattern="#{generalMessages.output_date_no_sec}"/>
<f:convertDateTime dateStyle="medium" timeStyle="short" timeZone="#{author.userTimeZone}" />
</h:outputText>
</h:column>
<h:column headerClass="extendedTime-retract">
<f:facet name="header">
<h:outputText value="#{assessmentSettingsMessages.header_extendedTime_retract_date}" />
</f:facet>
<h:outputText id="extendedTimeRetractDate" value="#{entry.retractDate}">
<f:convertDateTime pattern="#{generalMessages.output_date_no_sec}"/>
<f:convertDateTime dateStyle="medium" timeStyle="short" timeZone="#{author.userTimeZone}" />
</h:outputText>
</h:column>
<h:column headerClass="extendedTime-hours">
Expand Down
10 changes: 5 additions & 5 deletions samigo/samigo-app/src/webapp/jsf/author/publishedSettings.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -116,39 +116,39 @@
useTime: 1,
parseFormat: 'YYYY-MM-DD HH:mm:ss',
allowEmptyDate: true,
val: '<h:outputText value="#{publishedSettings.startDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/></h:outputText>',
val: '<h:outputText value="#{publishedSettings.startDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{author.userTimeZone}"/></h:outputText>',
ashidden: { iso8601: 'startDateISO8601' }
});
localDatePicker({
input: '#assessmentSettingsAction\\:endDate',
useTime: 1,
parseFormat: 'YYYY-MM-DD HH:mm:ss',
allowEmptyDate: true,
val: '<h:outputText value="#{publishedSettings.dueDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/></h:outputText>',
val: '<h:outputText value="#{publishedSettings.dueDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{author.userTimeZone}"/></h:outputText>',
ashidden: { iso8601: 'endDateISO8601' }
});
localDatePicker({
input: '#assessmentSettingsAction\\:retractDate',
useTime: 1,
parseFormat: 'YYYY-MM-DD HH:mm:ss',
allowEmptyDate: true,
val: '<h:outputText value="#{publishedSettings.retractDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/></h:outputText>',
val: '<h:outputText value="#{publishedSettings.retractDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{author.userTimeZone}"/></h:outputText>',
ashidden: { iso8601: 'retractDateISO8601' }
});
localDatePicker({
input: '#assessmentSettingsAction\\:feedbackDate',
useTime: 1,
parseFormat: 'YYYY-MM-DD HH:mm:ss',
allowEmptyDate: true,
val: '<h:outputText value="#{publishedSettings.feedbackDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/></h:outputText>',
val: '<h:outputText value="#{publishedSettings.feedbackDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{author.userTimeZone}"/></h:outputText>',
ashidden: { iso8601: 'feedbackDateISO8601' }
});
localDatePicker({
input: '#assessmentSettingsAction\\:feedbackEndDate',
useTime: 1,
parseFormat: 'YYYY-MM-DD HH:mm:ss',
allowEmptyDate: true,
val: '<h:outputText value="#{publishedSettings.feedbackEndDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/></h:outputText>',
val: '<h:outputText value="#{publishedSettings.feedbackEndDate}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" timeZone="#{author.userTimeZone}"/></h:outputText>',
ashidden: { iso8601: 'feedbackEndDateISO8601' }
});
localDatePicker({
Expand Down

0 comments on commit 80a7128

Please sign in to comment.