Skip to content

Commit

Permalink
use midnight as default time for date time picker
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Apr 11, 2024
1 parent ae815d2 commit 1ef5b41
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import java.io.Serial;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.chrono.IsoChronology;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.FormatStyle;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
Expand Down Expand Up @@ -104,6 +107,7 @@ public String toJsConfiguration() {
.append("', "));
sb.append("dayViewHeaderFormat: { month: 'long', year: 'numeric'}, ");


@NotNull Locale locale = LocalizationUtil.findLocale();
sb.append("locale: '").append(locale.toLanguageTag()).append("', ");

Expand All @@ -117,17 +121,21 @@ public String toJsConfiguration() {
.append(getDateTimeFormatForOption(locale))
.append("' ");

sb.append("}");
sb.append("},");

sb.append("useCurrent: false,");
sb.append("viewDate: '" + getCurrentDate(locale) + "'");
sb.append("}");
return sb.toString();
}

private String getCurrentDate(@NotNull Locale locale) {
return LocalDateTime.now().with(LocalTime.MIDNIGHT).format(DateTimeFormatter.ofPattern(getDefaultPattern(locale)));
}

public List<String> getDateTimeFormat() {
@NotNull Locale locale = LocalizationUtil.findLocale();
String localizedDatePattern = getDateTimeFormat(locale);

localizedDatePattern = replaceSpecificCharacters(localizedDatePattern);
String localizedDatePattern = getDefaultPattern(locale);

return List.of(
replaceSpecificCharacters(localizedDatePattern),
Expand All @@ -136,6 +144,10 @@ public List<String> getDateTimeFormat() {
);
}

private String getDefaultPattern(@NotNull Locale locale) {
return replaceSpecificCharacters(getDateTimeFormat(locale));
}

private String replaceSpecificCharacters(String localizedDatePattern) {
if (localizedDatePattern.contains("MMMM")) {
localizedDatePattern = localizedDatePattern.replaceAll("MMMM", "LLLL");
Expand Down

0 comments on commit 1ef5b41

Please sign in to comment.