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

[DO NOT MERGE] Test cleanup-deps #102

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 0 additions & 2 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ android {
}

dependencies {
implementation(projects.core.model)

// LifeCycle
implementation(libs.androidx.lifecycle.runtimeCompose)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
package com.wei.amazingtalker.core.extensions

import com.wei.amazingtalker.core.model.data.DuringDayType
import java.time.OffsetDateTime
import java.time.ZoneId
import java.time.ZoneOffset

/**
* 擴展 OffsetDateTime 類,根據當前時間返回是上午/下午/晚上。
* @return DuringDayType 返回一個 DuringDayType 類型的值,表示當前是上午、下午還是晚上。
*/
fun OffsetDateTime.getDuringDayType(): DuringDayType {
return when (this.hour) {
in 0..11 -> DuringDayType.Morning
in 12..17 -> DuringDayType.Afternoon
in 18..23 -> DuringDayType.Evening
else -> {
DuringDayType.Morning
}
}
}

/**
* 擴展 OffsetDateTime 類,根據系統默認的時區返回當地時間的 OffsetDateTime。
* @return OffsetDateTime 返回一個 OffsetDateTime 對象,表示當地時間。
Expand Down
8 changes: 4 additions & 4 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
}

dependencies {
implementation(projects.core.common)
implementation(projects.core.network)
implementation(projects.core.model)
implementation(projects.core.datastore)
api(projects.core.common)
api(projects.core.network)
api(projects.core.model)
api(projects.core.datastore)
}
3 changes: 0 additions & 3 deletions core/domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ android {
}

dependencies {
implementation(projects.core.common)
implementation(projects.core.data)
implementation(projects.core.model)
implementation(projects.core.network)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.wei.amazingtalker.core.domain

import com.wei.amazingtalker.core.extensions.getDuringDayType
import com.wei.amazingtalker.core.model.data.IntervalScheduleTimeSlot
import com.wei.amazingtalker.core.model.data.ScheduleState
import com.wei.amazingtalker.core.model.data.TimeSlots
import com.wei.amazingtalker.core.model.data.getDuringDayType
import java.time.Instant
import java.time.OffsetDateTime
import java.time.ZoneId
Expand All @@ -24,62 +24,62 @@ enum class TimeInterval(val value: Long) {
* @return MutableList<IntervalScheduleTimeSlot> 切分後的時間段物件的列表
*/
class IntervalizeScheduleUseCase
@Inject
constructor() {
private val currentTimezone = ZoneId.systemDefault()
@Inject
constructor() {
private val currentTimezone = ZoneId.systemDefault()

operator fun invoke(
teacherScheduleList: List<TimeSlots>,
timeInterval: TimeInterval,
scheduleState: ScheduleState,
): List<IntervalScheduleTimeSlot> {
return teacherScheduleList.flatMap { teacherSchedule ->
val startDateTime = utcToLocalTime(teacherSchedule.startUtc)
val endDateTime = utcToLocalTime(teacherSchedule.endUtc)
operator fun invoke(
teacherScheduleList: List<TimeSlots>,
timeInterval: TimeInterval,
scheduleState: ScheduleState,
): List<IntervalScheduleTimeSlot> {
return teacherScheduleList.flatMap { teacherSchedule ->
val startDateTime = utcToLocalTime(teacherSchedule.startUtc)
val endDateTime = utcToLocalTime(teacherSchedule.endUtc)

generateSequence(startDateTime) { it.plusMinutes(timeInterval.value) }
.takeWhile { it.isBefore(endDateTime) }
.map { createInterval(it, timeInterval.value, scheduleState, endDateTime) }
.toList()
generateSequence(startDateTime) { it.plusMinutes(timeInterval.value) }
.takeWhile { it.isBefore(endDateTime) }
.map { createInterval(it, timeInterval.value, scheduleState, endDateTime) }
.toList()
}
}
}

/**
* 創建時間段物件。
* @param startDateTime 開始時間。
* @param timeInterval 時間間隔(以分鐘為單位)。
* @param scheduleState 時間段的狀態。
* @param endDateTime 結束時間。
* @return IntervalScheduleTimeSlot 時間段物件。
*/
internal fun createInterval(
startDateTime: OffsetDateTime,
timeInterval: Long,
scheduleState: ScheduleState,
endDateTime: OffsetDateTime,
): IntervalScheduleTimeSlot {
val nextDateTime = startDateTime.plusMinutes(timeInterval)
if (nextDateTime.isAfter(endDateTime) && !nextDateTime.isEqual(endDateTime)) {
throw IllegalStateException("剩餘時間不足切分: $startDateTime, 欲切分至: $nextDateTime")
}
/**
* 創建時間段物件。
* @param startDateTime 開始時間。
* @param timeInterval 時間間隔(以分鐘為單位)。
* @param scheduleState 時間段的狀態。
* @param endDateTime 結束時間。
* @return IntervalScheduleTimeSlot 時間段物件。
*/
internal fun createInterval(
startDateTime: OffsetDateTime,
timeInterval: Long,
scheduleState: ScheduleState,
endDateTime: OffsetDateTime,
): IntervalScheduleTimeSlot {
val nextDateTime = startDateTime.plusMinutes(timeInterval)
if (nextDateTime.isAfter(endDateTime) && !nextDateTime.isEqual(endDateTime)) {
throw IllegalStateException("剩餘時間不足切分: $startDateTime, 欲切分至: $nextDateTime")
}

return IntervalScheduleTimeSlot(
startDateTime,
nextDateTime,
scheduleState,
startDateTime.getDuringDayType(),
)
}
return IntervalScheduleTimeSlot(
startDateTime,
nextDateTime,
scheduleState,
startDateTime.getDuringDayType(),
)
}

/**
* 將 UTC 時間轉換為本地時間。
* @param utcTime UTC 時間的字串表示。
* @return OffsetDateTime 本地時間的 OffsetDateTime 物件。
*/
private fun utcToLocalTime(utcTime: String): OffsetDateTime {
val utcInstant = Instant.parse(utcTime)
val localDateTime = ZonedDateTime.ofInstant(utcInstant, currentTimezone).toLocalDateTime()
val offset = currentTimezone.rules.getOffset(localDateTime)
return OffsetDateTime.of(localDateTime, offset)
/**
* 將 UTC 時間轉換為本地時間。
* @param utcTime UTC 時間的字串表示。
* @return OffsetDateTime 本地時間的 OffsetDateTime 物件。
*/
private fun utcToLocalTime(utcTime: String): OffsetDateTime {
val utcInstant = Instant.parse(utcTime)
val localDateTime = ZonedDateTime.ofInstant(utcInstant, currentTimezone).toLocalDateTime()
val offset = currentTimezone.rules.getOffset(localDateTime)
return OffsetDateTime.of(localDateTime, offset)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
package com.wei.amazingtalker.core.model.data

import java.time.OffsetDateTime

enum class DuringDayType {
Morning,
Afternoon,
Evening,
}

/**
* 擴展 OffsetDateTime 類,根據當前時間返回是上午/下午/晚上。
* @return DuringDayType 返回一個 DuringDayType 類型的值,表示當前是上午、下午還是晚上。
*/
fun OffsetDateTime.getDuringDayType(): DuringDayType {
return when (this.hour) {
in 0..11 -> DuringDayType.Morning
in 12..17 -> DuringDayType.Afternoon
in 18..23 -> DuringDayType.Evening
else -> {
DuringDayType.Morning
}
}
}
1 change: 0 additions & 1 deletion core/testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies {
implementation(projects.core.data)
implementation(projects.core.model)
implementation(projects.core.domain)
implementation(projects.core.network)
implementation(projects.core.designsystem)

api(libs.junit4)
Expand Down
Loading