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

SAK-48501 Site Manage use a proper date/time format #13072

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.time.ZoneId;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -2656,6 +2658,7 @@ else if (state.getAttribute(STATE_CM_REQUESTED_SECTIONS) != null) {
if(daysafter > 0){
context.put("daysafter",daysafter);
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor, but I believe you could just use withZone here and avoid having to do atZone later. And might also be "nice to have" to have it final. I'm fine with your preference if you tested this to work. Thanks for the fix!

final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss").withZone(localZoneId);

if (site != null) {
// editing existing site
context.put("site", site);
Expand Down Expand Up @@ -2689,9 +2692,14 @@ else if (state.getAttribute(STATE_CM_REQUESTED_SECTIONS) != null) {
ZoneId localZoneId = userTimeService.getLocalTimeZone().toZoneId();

termPublishDate = new Date(courseStartTime - (ONE_DAY_IN_MS * daysbefore));
context.put("termStartDate", termPublishDate.toInstant().atZone(localZoneId).toString());
context.put("termEndDate", new Date(courseEndTime).toInstant().atZone(localZoneId).toString());
context.put("termUnpublishDate", new Date(courseEndTime + (ONE_DAY_IN_MS * daysafter)).toInstant().atZone(localZoneId).toString());

ZonedDateTime termStartDate = termPublishDate.toInstant().atZone(localZoneId);
ZonedDateTime termEndDate = new Date(courseEndTime).toInstant().atZone(localZoneId);
ZonedDateTime termUnpublishDate = new Date(courseEndTime + (ONE_DAY_IN_MS * daysafter)).toInstant().atZone(localZoneId);

context.put("termStartDate", termStartDate.format(formatter));
context.put("termEndDate", termEndDate.format(formatter));
context.put("termUnpublishDate", termUnpublishDate.format(formatter));
context.put("readableTermStartDate", userTimeService.dateFormat(termPublishDate, rb.getLocale(), DateFormat.LONG)); //create readable versions of all dates
context.put("readableTermStartDateTime", userTimeService.dateTimeFormat(termPublishDate, rb.getLocale(), DateFormat.SHORT));
context.put("readableTermEndDate", userTimeService.dateFormat(academicSession.getEndDate(), rb.getLocale(), DateFormat.LONG));
Expand Down Expand Up @@ -2818,9 +2826,13 @@ else if (state.getAttribute(STATE_CM_REQUESTED_SECTIONS) != null) {
long courseEndTime = academicSession.getEndDate().getTime();
ZoneId localZoneId = userTimeService.getLocalTimeZone().toZoneId();

context.put("termStartDate", new Date(courseStartTime - (ONE_DAY_IN_MS * daysbefore)).toInstant().atZone(localZoneId).toString());
context.put("termEndDate", new Date(courseEndTime).toInstant().atZone(localZoneId).toString());
context.put("termUnpublishDate", new Date(courseEndTime + (ONE_DAY_IN_MS * daysafter)).toInstant().atZone(localZoneId).toString());
ZonedDateTime termStartDate = new Date(courseStartTime - (ONE_DAY_IN_MS * daysbefore)).toInstant().atZone(localZoneId);
ZonedDateTime termEndDate = new Date(courseEndTime).toInstant().atZone(localZoneId);
ZonedDateTime termUnpublishDate = new Date(courseEndTime + (ONE_DAY_IN_MS * daysafter)).toInstant().atZone(localZoneId);

context.put("termStartDate", termStartDate.format(formatter));
context.put("termEndDate", termEndDate.format(formatter));
context.put("termUnpublishDate", termUnpublishDate.format(formatter));
context.put("readableTermStartDate", userTimeService.dateFormat(new Date(courseStartTime - (ONE_DAY_IN_MS * daysbefore)), rb.getLocale(), DateFormat.LONG)); //create readable versions of all dates
context.put("readableTermEndDate", userTimeService.dateFormat(academicSession.getEndDate(), rb.getLocale(), DateFormat.LONG));
context.put("readableTermUnpublishDate", userTimeService.dateFormat(new Date(courseEndTime + (ONE_DAY_IN_MS * daysafter)), rb.getLocale(), DateFormat.LONG));
Expand Down
Loading