Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.mhss.app.ui.R
import com.mhss.app.util.date.at
import com.mhss.app.util.date.hour
import com.mhss.app.util.date.minute
import com.mhss.app.util.date.utcDateAt

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -54,7 +55,7 @@ fun DateTimeDialog(
onClick = {
if (showTime) {
onDatePicked(
datePickerState.selectedDateMillis?.at(
datePickerState.selectedDateMillis?.utcDateAt(
timePickerState.hour,
timePickerState.minute
) ?: initialDate
Expand Down Expand Up @@ -108,7 +109,7 @@ fun DateDialog(
TextButton(
onClick = {
onDatePicked(
datePickerState.selectedDateMillis?.at(
datePickerState.selectedDateMillis?.utcDateAt(
initialDate.hour,
initialDate.minute
) ?: initialDate
Expand Down
13 changes: 13 additions & 0 deletions core/util/src/main/java/com/mhss/app/util/date/DateUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ fun Long.at(hours: Int, minutes: Int): Long {
).toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds()
}

fun Long.utcDateAt(hours: Int, minutes: Int): Long {
val date = Instant.fromEpochMilliseconds(this).toLocalDateTime(TimeZone.UTC).date
return LocalDateTime(
year = date.year,
month = date.month,
day = date.day,
hour = hours,
minute = minutes,
second = 0,
nanosecond = 0
).toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds()
}

fun Long.toDayOfWeek(): DayOfWeek {
return Instant
.fromEpochMilliseconds(this)
Expand Down