-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bfd782
commit 1f82946
Showing
3 changed files
with
28 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ip-planner/domain/src/main/kotlin/xyz/ksharma/krail/trip_planner/domain/DateTimeHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,30 @@ | ||
package xyz.ksharma.krail.trip_planner.domain | ||
|
||
import java.time.ZoneId | ||
import java.time.ZonedDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
object DateTimeHelper { | ||
|
||
fun String.formatTo12HourTime(): String { | ||
// Parse the string as ZonedDateTime | ||
val zonedDateTime = ZonedDateTime.parse(this) | ||
|
||
// Define the formatter for 12-hour time with AM/PM | ||
val timeFormatter = DateTimeFormatter.ofPattern("h:mm a") | ||
|
||
// Format the ZonedDateTime to 12-hour format | ||
return zonedDateTime.format(timeFormatter) | ||
} | ||
|
||
|
||
fun String.utcToAEST(): String { | ||
// Parse the string as a ZonedDateTime in UTC | ||
val utcDateTime = ZonedDateTime.parse(this, DateTimeFormatter.ISO_ZONED_DATE_TIME) | ||
|
||
// Convert to AEST time zone (UTC+10) | ||
val aestZoneId = ZoneId.of("Australia/Sydney") | ||
val aestDateTime = utcDateTime.withZoneSameInstant(aestZoneId) | ||
return aestDateTime.format(DateTimeFormatter.ISO_DATE_TIME) | ||
} | ||
} |