Skip to content

Commit

Permalink
Support entry format for date component (#1897)
Browse files Browse the repository at this point in the history
* Support Entry format for date component

* spotless check applied

* review comments addressed

* review comments addressed

* review comment addressed

* Add tests from previous pr

* Move entry format function to extensions package

* Reorganize MoreQuestionnaireItemComponents.kt file

* Add tests in MoreQuestionnaireItemComponentsTest.kt

* Add comment and rename function name

* Add back enable when expression utility

---------

Co-authored-by: Jing Tang <[email protected]>
  • Loading branch information
PallaviGanorkar and jingtang10 authored Aug 31, 2023
1 parent 4a75e6b commit 22ab365
Show file tree
Hide file tree
Showing 15 changed files with 660 additions and 409 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Google LLC
* Copyright 2022-2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,15 +23,19 @@ import java.lang.Character.isLetter
import java.text.ParseException
import java.time.LocalDate
import java.time.ZoneId
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.Locale

/**
* Returns the first character that is not a letter in the given date pattern string (e.g. "/" for
* "dd/mm/yyyy").
* "dd/mm/yyyy") otherwise null.
*/
internal fun getDateSeparator(localeDatePattern: String): Char =
localeDatePattern.filterNot { isLetter(it) }.first()
internal fun getDateSeparator(localeDatePattern: String): Char? =
localeDatePattern.filterNot { isLetter(it) }.firstOrNull()

/**
* Converts date pattern to acceptable date pattern where 2 digits are expected for day(dd) and
Expand Down Expand Up @@ -112,3 +116,16 @@ internal fun LocalDate.format(pattern: String? = null): String {
DateTimeFormatter.ofPattern(pattern).format(this)
}
}

/**
* Medium and long format styles use alphabetical month names which are difficult for the user to
* input. Use short format style which is always numerical.
*/
internal fun getLocalizedDatePattern(): String {
return DateTimeFormatterBuilder.getLocalizedDateTimePattern(
FormatStyle.SHORT,
null,
IsoChronology.INSTANCE,
Locale.getDefault()
)
}
Loading

0 comments on commit 22ab365

Please sign in to comment.