-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
16 changed files
with
131 additions
and
31 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
10 changes: 5 additions & 5 deletions
10
data/src/main/java/com/teamtuna/emotionaldiary/DateConverter.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,17 +1,17 @@ | ||
package com.teamtuna.emotionaldiary | ||
|
||
import androidx.room.TypeConverter | ||
import java.util.Date | ||
import java.time.LocalDateTime | ||
|
||
object DateConverter { | ||
|
||
@TypeConverter | ||
fun toDate(value: Long?): Date? { | ||
return value?.let { Date(it) } | ||
fun toDate(value: Long?): LocalDateTime? { | ||
return value?.let { it.toLocalDateTime() } | ||
} | ||
|
||
@TypeConverter | ||
fun fromDate(date: Date?): Long? { | ||
return date?.time | ||
fun fromDate(date: LocalDateTime?): Long? { | ||
return date?.getTime() | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
data/src/main/java/com/teamtuna/emotionaldiary/TimeUtil.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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.teamtuna.emotionaldiary | ||
|
||
import java.time.Instant | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.time.LocalTime | ||
import java.time.Period | ||
import java.time.ZoneId | ||
import java.util.Date | ||
|
||
fun Date.convertInstant(): Instant { | ||
return Instant.ofEpochMilli(this.time) | ||
} | ||
|
||
fun Int.toLocalDateSecondTime(): LocalDateTime { | ||
return (this * 1000L).toLocalDateTime() | ||
} | ||
|
||
fun Int.toLocalDate(): LocalDate { | ||
return (this * 1000L).toLocalDate() | ||
} | ||
|
||
fun Int.toLocalTime(): LocalTime { | ||
return toLocalDateSecondTime().toLocalTime() | ||
} | ||
|
||
fun Int.timeInMills(): Long { | ||
return this.toLocalDateSecondTime().getTime() | ||
} | ||
|
||
fun Long.toLocalDateTime(): LocalDateTime { | ||
return LocalDateTime.ofInstant(Date(this).convertInstant(), ZoneId.systemDefault()) | ||
} | ||
|
||
fun Long.toLocalDate(): LocalDate { | ||
return Instant.ofEpochMilli(this).atZone(ZoneId.systemDefault()).toLocalDate() | ||
} | ||
|
||
fun Long.timeInSeconds(): Int { | ||
return ((this / 1000L).toInt()) | ||
} | ||
|
||
fun LocalDateTime.getDayOfDateTime(): LocalDateTime { | ||
return this | ||
.withHour(0) | ||
.withMinute(0) | ||
.withSecond(0) | ||
} | ||
|
||
fun LocalDateTime.getDayOfTime(): Long { | ||
return this | ||
.withHour(0) | ||
.withMinute(0) | ||
.withSecond(0) | ||
.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() | ||
} | ||
|
||
fun LocalDateTime.getTime(): Long { | ||
return this.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() | ||
} | ||
|
||
fun Long.isToday(): Boolean { | ||
val period = Period.between(LocalDate.now(), toLocalDateTime().toLocalDate()) | ||
return period.years == 0 && period.months == 0 && period.days == 0 | ||
} | ||
|
||
fun Long.isYesterday(): Boolean { | ||
val period = Period.between(LocalDate.now(), toLocalDateTime().toLocalDate()) | ||
return period.years == 0 && period.months == 0 && period.days == -1 | ||
} | ||
|
||
fun Long.isPastYear(): Boolean { | ||
return LocalDate.now().year > toLocalDateTime().toLocalDate().year | ||
} | ||
|
||
fun Long.beforeCurrentTime(): Boolean { | ||
return this < System.currentTimeMillis() | ||
} | ||
|
||
fun epoch(year: Int, month: Int, dayOfMonth: Int): Int { | ||
return LocalDateTime.now().withYear(year).withMonth(month).withDayOfMonth(dayOfMonth) | ||
.atZone(ZoneId.systemDefault()).toEpochSecond().toInt() | ||
} |
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
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
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
9 changes: 7 additions & 2 deletions
9
domain/src/main/java/com/teamtuna/emotionaldiary/entity/DailyEmotion.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,7 +1,12 @@ | ||
package com.teamtuna.emotionaldiary.entity | ||
|
||
import java.util.Date | ||
import java.time.LocalDateTime | ||
|
||
data class DailyEmotion(val id: UniqId, val emotion: Emotion, val date: Date, val reason: String) | ||
data class DailyEmotion( | ||
val id: UniqId, | ||
val emotion: Emotion, | ||
val date: LocalDateTime, | ||
val reason: String | ||
) | ||
|
||
typealias UniqId = Long |
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
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
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