Skip to content

Commit

Permalink
Event invites: fix issue with times showing wrong across timezones.
Browse files Browse the repository at this point in the history
Fixes #52.
  • Loading branch information
tasn committed Dec 24, 2018
1 parent 0a6fd19 commit 4184751
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,16 @@ private String formatAttendees(List<Attendee> attendeesList) {

private static String formatEventDates(Event event) {
final Locale locale = Locale.getDefault();
final TimeZone timezone = event.dtStart.getTimeZone();
final String dateFormatString =
event.isAllDay() ? "EEEE, MMM dd" : "EEEE, MMM dd @ hh:mm a";
final DateFormat dateFormat =
final DateFormat longDateFormat =
new SimpleDateFormat(dateFormatString, locale);
final TimeZone timezone = event.dtStart.getTimeZone();
longDateFormat.setTimeZone(timezone);
final DateFormat shortDateFormat =
new SimpleDateFormat("hh:mm a", locale);
shortDateFormat.setTimeZone(timezone);

Date startDate = event.dtStart.getDate();
Date endDate = event.getEndDate(true).getDate();
final String tzName = (timezone != null) ?
Expand All @@ -241,14 +246,14 @@ private static String formatEventDates(Event event) {
boolean sameDay = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
if (sameDay && event.isAllDay()) {
return dateFormat.format(startDate);
return longDateFormat.format(startDate);
}
return sameDay ?
String.format("%s - %s (%s)",
dateFormat.format(startDate),
new SimpleDateFormat("hh:mm a", locale).format(endDate),
longDateFormat.format(startDate),
shortDateFormat.format(endDate),
tzName) :
String.format("%s - %s (%s)", dateFormat.format(startDate), dateFormat.format(endDate), tzName);
String.format("%s - %s (%s)", longDateFormat.format(startDate), longDateFormat.format(endDate), tzName);
}

private Uri createAttachmentFromString(Context context, String name, String content) {
Expand Down

0 comments on commit 4184751

Please sign in to comment.