forked from upstream-mirrors/OpenTracks
@@ -99,7 +99,7 @@ public class DescriptionGeneratorTest {
|
||||
+ "Min elevation: -500 m (-1640 ft)<br>"
|
||||
+ "Elevation gain: 6000 m (19685 ft)<br>"
|
||||
+ "Elevation loss: 6000 m (19685 ft)<br>"
|
||||
+ "Recorded: " + StringUtils.formatDateTime(OffsetDateTime.ofInstant(START_TIME, ZoneId.systemDefault())) + "<br>";
|
||||
+ "Recorded: " + StringUtils.formatDateTimeWithOffset(OffsetDateTime.ofInstant(START_TIME, ZoneId.systemDefault())) + "<br>";
|
||||
|
||||
assertEquals(expected, descriptionGenerator.generateTrackDescription(track, true));
|
||||
}
|
||||
@@ -135,7 +135,7 @@ public class DescriptionGeneratorTest {
|
||||
+ "Fastest pace: 0:10 min/km (0:16 min/mi)<br>"
|
||||
+ "Elevation gain: 6000 m (19685 ft)<br>"
|
||||
+ "Elevation loss: 6000 m (19685 ft)<br>"
|
||||
+ "Recorded: " + StringUtils.formatDateTime(OffsetDateTime.ofInstant(START_TIME, ZoneId.systemDefault())) + "<br>";
|
||||
+ "Recorded: " + StringUtils.formatDateTimeWithOffset(OffsetDateTime.ofInstant(START_TIME, ZoneId.systemDefault())) + "<br>";
|
||||
|
||||
assertEquals(expected, descriptionGenerator.generateTrackDescription(track, true));
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class StatisticsRecordedFragment extends Fragment {
|
||||
private void loadTrackDescription(@NonNull Track track) {
|
||||
viewBinding.statsNameValue.setText(track.getName());
|
||||
viewBinding.statsDescriptionValue.setText(track.getDescription());
|
||||
viewBinding.statsStartDatetimeValue.setText(StringUtils.formatDateTime(track.getStartTime()));
|
||||
viewBinding.statsStartDatetimeValue.setText(StringUtils.formatDateTimeWithOffsetIfDifferent(track.getStartTime()));
|
||||
}
|
||||
|
||||
private void updateUI() {
|
||||
|
||||
@@ -153,7 +153,7 @@ public class DescriptionGenerator {
|
||||
}
|
||||
|
||||
// Recorded time
|
||||
builder.append(context.getString(R.string.description_recorded_time, StringUtils.formatDateTime(OffsetDateTime.ofInstant(stats.getStartTime(), ZoneId.systemDefault()))));
|
||||
builder.append(context.getString(R.string.description_recorded_time, StringUtils.formatDateTimeWithOffset(OffsetDateTime.ofInstant(stats.getStartTime(), ZoneId.systemDefault()))));
|
||||
builder.append(lineBreak);
|
||||
|
||||
return builder.toString();
|
||||
|
||||
@@ -108,7 +108,11 @@ public class ListItemUtils {
|
||||
String timeValue = null;
|
||||
if (!isRecording) {
|
||||
dateValue = StringUtils.formatDateTodayRelative(context, offsetDateTime);
|
||||
timeValue = offsetDateTime.format(DateTimeFormatter.ofPattern("HH:mm"));
|
||||
String pattern = "HH:mm";
|
||||
if (!offsetDateTime.getOffset().equals(OffsetDateTime.now().getOffset())) {
|
||||
pattern = "HH:mm x";
|
||||
}
|
||||
timeValue = offsetDateTime.format(DateTimeFormatter.ofPattern(pattern));
|
||||
}
|
||||
setTextView(context, dateTextView, dateValue, hasPhoto);
|
||||
setTextView(context, timeTextView, timeValue, hasPhoto);
|
||||
|
||||
@@ -61,13 +61,6 @@ public class StringUtils {
|
||||
private StringUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the date and time of the OffsetDateTime (using default Locale format)
|
||||
*/
|
||||
public static String formatDateTime(OffsetDateTime odt) {
|
||||
return odt.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the date and time with the offset (using default Locale format).
|
||||
*/
|
||||
@@ -75,6 +68,13 @@ public class StringUtils {
|
||||
return odt.toZonedDateTime().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL));
|
||||
}
|
||||
|
||||
public static String formatDateTimeWithOffsetIfDifferent(OffsetDateTime odt) {
|
||||
if (!odt.getOffset().equals(OffsetDateTime.now().getOffset())) {
|
||||
return odt.toZonedDateTime().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL));
|
||||
}
|
||||
return odt.toZonedDateTime().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM));
|
||||
}
|
||||
|
||||
public static String formatLocalDateTime(LocalDateTime localDateTime) {
|
||||
return localDateTime.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user