Открыть боковую панель
effective-dev-opensource
Effective-Office
Коммиты
674bfbf5
Не подтверждена
Коммит
674bfbf5
создал
Июл 31, 2025
по автору
Vitaly.Smirnov
Зафиксировано автором
GitHub
Июл 31, 2025
Просмотр файлов
feat: Add localized time format 12h and 24h (#353)
владелец
3b7f1aaf
Изменения
6
Скрыть пробелы
Построчно
Рядом
clients/tablet/core/ui/src/androidMain/kotlin/band/effective/office/tablet/core/ui/util/DateFormatter.android.kt
Просмотр файла @
674bfbf5
...
...
@@ -8,4 +8,6 @@ import java.util.Locale
actual
fun
LocalDateTime
.
toLocalisedString
(
pattern
:
String
):
String
{
val
formatter
=
DateTimeFormatter
.
ofPattern
(
pattern
,
Locale
.
getDefault
())
return
this
.
toJavaLocalDateTime
().
format
(
formatter
)
}
\ Нет новой строки в конце файла
}
actual
fun
getCurrentLanguageCode
():
String
=
Locale
.
getDefault
().
language
\ Нет новой строки в конце файла
clients/tablet/core/ui/src/commonMain/kotlin/band/effective/office/tablet/core/ui/utils/DateDisplayMapper.kt
Просмотр файла @
674bfbf5
package
band.effective.office.tablet.core.ui.utils
import
kotlinx.datetime.LocalDateTime
/**
* Data class to store date and time format patterns for a specific locale.
*
* @param default Format for full date and time.
* @param future Format for future dates.
* @param time Format for time only.
*/
private
data class
LocaleFormatPatterns
(
val
default
:
String
,
val
future
:
String
,
val
time
:
String
)
/**
* Utility object for formatting dates and times based on the current locale.
* Falls back to English formats for unsupported locales.
*/
object
DateDisplayMapper
{
private
const
val
FUTURE_DATE_FORMAT
=
"d MMMM"
private
const
val
DEFAULT_DATE_FORMAT
=
"HH:mm, d MMMM"
private
val
formatPatterns
:
Map
<
String
,
LocaleFormatPatterns
>
=
mapOf
(
"ru"
to
LocaleFormatPatterns
(
default
=
"d MMMM, HH:mm"
,
future
=
"d MMMM"
,
time
=
"HH:mm"
),
"en"
to
LocaleFormatPatterns
(
default
=
"MMM d h:mm a"
,
future
=
"MMM d"
,
time
=
"h:mm a"
)
)
private
val
defaultFormats
:
LocaleFormatPatterns
=
formatPatterns
[
"en"
]
!!
private
fun
getPatternsForLocale
():
LocaleFormatPatterns
{
val
currentLanguage
=
getCurrentLanguageCode
()
return
formatPatterns
[
currentLanguage
]
?:
defaultFormats
}
fun
map
(
selectDate
:
LocalDateTime
,
currentDate
:
LocalDateTime
?):
String
{
val
isFutureDate
=
currentDate
!=
null
&&
selectDate
.
date
>
currentDate
.
date
val
pattern
=
if
(
isFutureDate
)
FUTURE_DATE_FORMAT
else
DEFAULT_DATE_FORMAT
val
patterns
=
getPatternsForLocale
()
val
pattern
=
if
(
currentDate
!=
null
&&
selectDate
.
date
>
currentDate
.
date
)
{
patterns
.
future
}
else
{
patterns
.
default
}
return
selectDate
.
toLocalisedString
(
pattern
)
}
fun
formatForPicker
(
date
:
LocalDateTime
):
String
{
return
date
.
toLocalisedString
(
FUTURE_DATE_FORMAT
)
val
patterns
=
getPatternsForLocale
()
return
date
.
toLocalisedString
(
patterns
.
future
)
}
fun
formatTime
(
time
:
LocalDateTime
):
String
{
val
patterns
=
getPatternsForLocale
()
return
time
.
toLocalisedString
(
patterns
.
time
)
}
}
\ Нет новой строки в конце файла
clients/tablet/core/ui/src/commonMain/kotlin/band/effective/office/tablet/core/ui/utils/DateFormatter.kt
Просмотр файла @
674bfbf5
...
...
@@ -4,3 +4,4 @@ import kotlinx.datetime.LocalDateTime
@OptIn
(
kotlinx
.
datetime
.
format
.
FormatStringsInDatetimeFormats
::
class
)
expect
fun
LocalDateTime
.
toLocalisedString
(
pattern
:
String
):
String
expect
fun
getCurrentLanguageCode
():
String
\ Нет новой строки в конце файла
clients/tablet/core/ui/src/iosMain/kotlin/band/effective/office/tablet/core/ui/utils/DateFormatter.ios.kt
Просмотр файла @
674bfbf5
...
...
@@ -20,4 +20,6 @@ actual fun LocalDateTime.toLocalisedString(pattern: String): String {
val
date
=
calendar
.
dateFromComponents
(
dateComponents
)
?:
NSDate
()
return
dateFormatter
.
stringFromDate
(
date
)
}
\ Нет новой строки в конце файла
}
actual
fun
getCurrentLanguageCode
():
String
=
NSLocale
.
currentLocale
.
languageCode
\ Нет новой строки в конце файла
clients/tablet/feature/slot/src/commonMain/kotlin/band/effective/office/tablet/feature/slot/presentation/components/CommonSlotView.kt
Просмотр файла @
674bfbf5
...
...
@@ -9,9 +9,9 @@ import androidx.compose.runtime.Composable
import
androidx.compose.ui.Alignment
import
androidx.compose.ui.Modifier
import
androidx.compose.ui.graphics.Color
import
band.effective.office.tablet.core.domain.util.toFormattedString
import
band.effective.office.tablet.core.ui.theme.h5
import
band.effective.office.tablet.core.ui.theme.h7
import
band.effective.office.tablet.core.ui.utils.DateDisplayMapper
import
band.effective.office.tablet.feature.slot.presentation.SlotUi
@Composable
...
...
@@ -28,7 +28,7 @@ fun CommonSlotView(
)
{
Column
{
Text
(
text
=
"${
slot.start.toFormattedString("
HH
:
mm
"
)}
-
${
slot.finish.toFormattedString("
HH
:
mm
"
)}"
,
text
=
"${
DateDisplayMapper.formatTime(slot.start
)}
—
${
DateDisplayMapper.formatTime(slot.finish
)}"
,
style
=
MaterialTheme
.
typography
.
h5
,
color
=
MaterialTheme
.
colorScheme
.
onPrimary
)
...
...
clients/tablet/feature/slot/src/commonMain/kotlin/band/effective/office/tablet/feature/slot/presentation/components/LoadingSlotView.kt
Просмотр файла @
674bfbf5
...
...
@@ -9,11 +9,11 @@ import androidx.compose.runtime.Composable
import
androidx.compose.ui.Alignment
import
androidx.compose.ui.Modifier
import
androidx.compose.ui.graphics.Color
import
band.effective.office.tablet.core.domain.util.toFormattedString
import
band.effective.office.tablet.core.ui.Res
import
band.effective.office.tablet.core.ui.loading_slot_for_time
import
band.effective.office.tablet.core.ui.theme.h5
import
band.effective.office.tablet.core.ui.theme.h7
import
band.effective.office.tablet.core.ui.utils.DateDisplayMapper
import
band.effective.office.tablet.feature.slot.presentation.SlotUi
import
org.jetbrains.compose.resources.stringResource
...
...
@@ -33,8 +33,8 @@ fun LoadingSlotView(
Text
(
text
=
stringResource
(
Res
.
string
.
loading_slot_for_time
,
slot
.
start
.
toFormattedString
(
"HH:mm"
),
slot
.
finish
.
toFormattedString
(
"HH:mm"
)
DateDisplayMapper
.
formatTime
(
slot
.
start
),
DateDisplayMapper
.
formatTime
(
slot
.
finish
)
),
style
=
MaterialTheme
.
typography
.
h5
,
color
=
MaterialTheme
.
colorScheme
.
onPrimary
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать