Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DateTimehelper functions #54

Merged
merged 4 commits into from
Sep 20, 2024
Merged
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
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dependencies {
implementation(projects.feature.sydneyTrains.database.real)
implementation(projects.feature.sydneyTrains.network.api)
implementation(projects.feature.sydneyTrains.network.real)
implementation(projects.feature.tripPlanner.domain) // TODO not really required remove it later
implementation(projects.feature.tripPlanner.network.api)
implementation(projects.feature.tripPlanner.network.real)

Expand Down
38 changes: 36 additions & 2 deletions app/src/main/java/xyz/ksharma/krail/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import timber.log.Timber
import xyz.ksharma.krail.design.system.theme.StartTheme
import xyz.ksharma.krail.trip_planner.domain.DateTimeHelper.formatTo12HourTime
import xyz.ksharma.krail.trip_planner.domain.DateTimeHelper.utcToAEST
import xyz.ksharma.krail.trip_planner.network.api.model.StopType
import xyz.ksharma.krail.trip_planner.network.api.repository.TripPlanningRepository
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -26,13 +31,42 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge()

lifecycleScope.launch {
var x =
var x = tripPlanningRepo.stopFinder(
stopType = StopType.ANY,
stopSearchQuery = "Seven Hills"
)
Timber.d("Seven Hills: ${x.getOrNull()?.locations?.map { it.productClasses.contains(1) }}")
x =
tripPlanningRepo.stopFinder(stopType = StopType.ANY, stopSearchQuery = "Central")
Timber.d("ANY: ${x.getOrNull()?.locations?.map { it.productClasses.contains(1) }}")
Timber.d("Central: ${x.getOrNull()?.locations?.map { it.productClasses.contains(1) }}")
x =
tripPlanningRepo.stopFinder(stopType = StopType.ANY, stopSearchQuery = "Townhall")
Timber.d("Townhall: ${x.getOrNull()?.locations?.map { it.productClasses.contains(1) }}")
x =
tripPlanningRepo.stopFinder(stopType = StopType.ANY, stopSearchQuery = "Rockdale")
Timber.d("Rockdale: ${x.getOrNull()?.locations?.map { it.productClasses.contains(1) }}")


var tripResponse = tripPlanningRepo.trip()
tripResponse.onSuccess { trip ->
Timber.d("Journeys: ${trip.journeys.size}")

trip.journeys.map {
it.legs.forEach {
Timber.d(
"departureTimeEstimated: ${
it.origin.departureTimeEstimated?.utcToAEST()?.formatTo12HourTime()
}," +
" Destination: ${
it.destination.arrivalTimeEstimated?.utcToAEST()
?.formatTo12HourTime()
}, " +
"Duration: ${it.duration}, " +
"transportation: ${it.transportation}",
)
}
}

}.onFailure {
Timber.e("error: ${it.message}")
}
Expand Down
7 changes: 7 additions & 0 deletions feature/trip-planner/domain/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
alias(libs.plugins.krail.android.library)
}

android {
namespace = "xyz.ksharma.krail.trip_planner.demain"
}
Original file line number Diff line number Diff line change
@@ -0,0 +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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ data class TripResponse(
@SerialName("origin") val origin: StopSequenceClass,
@SerialName("destination") val destination: StopSequenceClass,
@SerialName("pathDescriptions") val pathDescriptions: List<PathDescription>? = null,
@SerialName("isRealtimeControlled") val isRealtimeControlled: Boolean,
@SerialName("isRealtimeControlled") val isRealtimeControlled: Boolean? = null,
@SerialName("transportation") val transportation: Transportation,

/**
* In seconds
*/
@SerialName("duration") val duration: Long,
@SerialName("footPathInfo") val footPathInfo: List<FootPathInfo>? = null,
@SerialName("coords") val coords: List<List<Double>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ class RealTripPlanningRepository @Inject constructor(
).toSafeResult()
}
}

/**
* Rockdale - 221620
* Central - 200060
* TownHall -
*/
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ include(":feature:sydney-trains:model")
include(":feature:sydney-trains:network:api")
include(":feature:sydney-trains:network:real")
include(":feature:sydney-trains:ui")
include(":feature:trip-planner:domain")
include(":feature:trip-planner:network:api")
include(":feature:trip-planner:network:real")