aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt
diff options
context:
space:
mode:
Diffstat (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt45
1 files changed, 26 insertions, 19 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt
index 64df79d..6c86d27 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt
@@ -29,81 +29,86 @@ class ReportDates {
val dateTime = instant.toLocalDateTime(timezone)
val date = dateTime.date
- abstract fun getDates(): Pair<String, String>
+ abstract fun getObjectDates(): Pair<LocalDateTime, LocalDateTime>
+
+ fun getStringDates(): Pair<String, String> {
+ val (from, to) = getObjectDates()
+ return formatDateTime(from) to formatDateTime(to)
+ }
fun formatDateTime(dateTime: LocalDateTime) =
dateTime.toInstant(timezone).toString()
class Today : ReportPeriod() {
- override fun getDates(): Pair<String, String> {
+ override fun getObjectDates(): Pair<LocalDateTime, LocalDateTime> {
val from = date.atTime(0, 0)
val to = dateTime
- return formatDateTime(to) to formatDateTime(from)
+ return from to to
}
}
class Last24 : ReportPeriod() {
- override fun getDates(): Pair<String, String> {
+ override fun getObjectDates(): Pair<LocalDateTime, LocalDateTime> {
val from = instant
.minus(1, DateTimeUnit.DAY, timezone)
.toLocalDateTime(timezone)
val to = dateTime
- return formatDateTime(to) to formatDateTime(from)
+ return from to to
}
}
class Yesterday : ReportPeriod() {
- override fun getDates(): Pair<String, String> {
+ override fun getObjectDates(): Pair<LocalDateTime, LocalDateTime> {
val yesterday = instant
.minus(1, DateTimeUnit.DAY, timezone)
.toLocalDateTime(timezone).date
val from = yesterday.atTime(0, 0)
val to = yesterday.atTime(23, 59)
- return formatDateTime(to) to formatDateTime(from)
+ return from to to
}
}
class ThisWeek : ReportPeriod() {
- override fun getDates(): Pair<String, String> {
+ override fun getObjectDates(): Pair<LocalDateTime, LocalDateTime> {
val from = instant
.minus(date.dayOfWeek.isoDayNumber - 1, DateTimeUnit.DAY, timezone)
.toLocalDateTime(timezone).date
.atTime(0, 0)
val to = dateTime
- return formatDateTime(to) to formatDateTime(from)
+ return from to to
}
}
class Last7 : ReportPeriod() {
- override fun getDates(): Pair<String, String> {
+ override fun getObjectDates(): Pair<LocalDateTime, LocalDateTime> {
val from = instant
.minus(1, DateTimeUnit.WEEK, timezone)
.toLocalDateTime(timezone).date
.atTime(0, 0)
val to = dateTime
- return formatDateTime(to) to formatDateTime(from)
+ return from to to
}
}
class ThisMonth : ReportPeriod() {
- override fun getDates(): Pair<String, String> {
+ override fun getObjectDates(): Pair<LocalDateTime, LocalDateTime> {
val from = instant
.minus(date.dayOfMonth - 1, DateTimeUnit.DAY, timezone)
.toLocalDateTime(timezone).date
.atTime(0, 0)
val to = dateTime
- return formatDateTime(to) to formatDateTime(from)
+ return from to to
}
}
class Last30 : ReportPeriod() {
- override fun getDates(): Pair<String, String> {
+ override fun getObjectDates(): Pair<LocalDateTime, LocalDateTime> {
val from = instant
.minus(1, DateTimeUnit.MONTH, timezone)
.toLocalDateTime(timezone).date
.atTime(0, 0)
val to = dateTime
- return formatDateTime(to) to formatDateTime(from)
+ return from to to
}
}
@@ -111,13 +116,15 @@ class ReportDates {
private val from: LocalDateTime? = null,
private val to: LocalDateTime? = null
) : ReportPeriod() {
- override fun getDates(): Pair<String, String> {
- return formatDateTime(
+ override fun getObjectDates(): Pair<LocalDateTime, LocalDateTime> {
+ return Pair(
+ from ?: date.atTime(0, 0),
to ?: dateTime
- ) to formatDateTime(
- from ?: date.atTime(0, 0)
)
}
+
+ fun withFrom (from: LocalDateTime): Custom = Custom (from, to)
+ fun withTo (to: LocalDateTime): Custom = Custom (from, to)
}
}
} \ No newline at end of file