aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx/trackermap
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-04-11 00:55:26 -0500
committerIván Ávalos <avalos@disroot.org>2022-04-11 00:55:26 -0500
commit546738888395565ac2d5fe2cfb941ecdd0c1df45 (patch)
tree7f9646939b65dfbb97f0724c66d7a81e9bd5a23a /shared/src/commonMain/kotlin/mx/trackermap
parenta6a95167dbfe48fa0c5d6b61219309d346142979 (diff)
downloadetbsa-trackermap-mobile-546738888395565ac2d5fe2cfb941ecdd0c1df45.tar.gz
etbsa-trackermap-mobile-546738888395565ac2d5fe2cfb941ecdd0c1df45.tar.bz2
etbsa-trackermap-mobile-546738888395565ac2d5fe2cfb941ecdd0c1df45.zip
- [shared] Added DateUtils 'expect' class for platform-specific date format.
- [android] Redesigned reports view, now supports custom reports! - [ios] Not rewritten yet, it won't build!
Diffstat (limited to 'shared/src/commonMain/kotlin/mx/trackermap')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt15
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/DateUtils.kt9
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt5
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt45
4 files changed, 44 insertions, 30 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt
index e120e97..bc0a48f 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt
@@ -60,18 +60,17 @@ class ReportController(
return
}
- val (currentDate, previousDate) = reportPeriod.getDates()
+ val (from, to) = reportPeriod.getStringDates()
if (!xlsx) {
reportFlow.value = Report.LoadingReport
}
- // GlobalScope.launch {
- when (reportType) {
- ReportType.POSITIONS -> fetchPositions(deviceId, previousDate, currentDate, xlsx)
- ReportType.EVENTS -> fetchEvents(deviceId, previousDate, currentDate, eventTypes, xlsx)
- ReportType.STOPS -> fetchStops(deviceId, previousDate, currentDate, xlsx)
- }
- // }
+
+ when (reportType) {
+ ReportType.POSITIONS -> fetchPositions(deviceId, from, to, xlsx)
+ ReportType.EVENTS -> fetchEvents(deviceId, from, to, eventTypes, xlsx)
+ ReportType.STOPS -> fetchStops(deviceId, from, to, xlsx)
+ }
}
private suspend fun fetchPositions(
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/DateUtils.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/DateUtils.kt
new file mode 100644
index 0000000..a85ae69
--- /dev/null
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/DateUtils.kt
@@ -0,0 +1,9 @@
+package mx.trackermap.TrackerMap.utils
+
+import kotlinx.datetime.LocalDateTime
+
+expect class DateUtils {
+ companion object {
+ fun formatDate(date: LocalDateTime): String
+ }
+} \ No newline at end of file
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt
index 77d0d14..bc7e622 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt
@@ -23,9 +23,8 @@ class Formatter {
companion object {
fun formatDate(str: String): String {
val timezone = TimeZone.currentSystemDefault()
- val date = str.toInstant().toLocalDateTime(timezone).toString()
- return date
- .replace('T', ' ').trim('Z')
+ val datetime = str.toInstant().toLocalDateTime(timezone)
+ return DateUtils.formatDate(datetime)
}
fun formatSpeed(speed: Double, unit: SpeedUnit): String {
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