From 0b3bdc6557cbfc1d8e7bf4052e93cf97cac8b943 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Fri, 8 Nov 2024 15:29:25 +0100 Subject: [PATCH 1/2] feat: Add JavaDateExt --- .../common/ext/JavaDateExt.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 STCommon/src/androidMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/ext/JavaDateExt.kt diff --git a/STCommon/src/androidMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/ext/JavaDateExt.kt b/STCommon/src/androidMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/ext/JavaDateExt.kt new file mode 100644 index 00000000..d8d52726 --- /dev/null +++ b/STCommon/src/androidMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/ext/JavaDateExt.kt @@ -0,0 +1,22 @@ +/* + * Infomaniak SwissTransfer - Multiplatform + * Copyright (C) 2024 Infomaniak Network SA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.infomaniak.multiplatform_swisstransfer.common.ext + +import java.util.Date + +fun Long.toDateFromSeconds() = Date(this * 1000) From 6ef44f6d03ccc86949659f5c682c0ad011cf167e Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Fri, 8 Nov 2024 15:30:19 +0100 Subject: [PATCH 2/2] refactor: Replace all timestamp millis to seconds --- .../common/interfaces/ui/TransferUi.kt | 2 +- .../multiplatform_swisstransfer/common/utils/DateUtils.kt | 4 ++-- .../network/serializers/DateToTimestampSerializer.kt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/ui/TransferUi.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/ui/TransferUi.kt index e2e477c3..e50ddb7f 100644 --- a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/ui/TransferUi.kt +++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/ui/TransferUi.kt @@ -33,7 +33,7 @@ data class TransferUi( val files: List, ) { - val expiresInDays: Int = DateUtils.timestampToDays(expirationDateTimestamp - Clock.System.now().toEpochMilliseconds()).toInt() + val expiresInDays: Int = DateUtils.timestampToDays(expirationDateTimestamp - Clock.System.now().epochSeconds).toInt() constructor(transfer: Transfer) : this( uuid = transfer.linkUUID, diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/utils/DateUtils.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/utils/DateUtils.kt index cf337ab5..627c88f7 100644 --- a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/utils/DateUtils.kt +++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/utils/DateUtils.kt @@ -19,7 +19,7 @@ package com.infomaniak.multiplatform_swisstransfer.common.utils internal object DateUtils { - private const val MILLISECONDS_IN_A_DAY = 24 * 60 * 60 * 1_000L + private const val SECONDS_IN_A_DAY = 24 * 60 * 60 - fun timestampToDays(timestamp: Long) = timestamp / MILLISECONDS_IN_A_DAY + fun timestampToDays(timestamp: Long) = timestamp / SECONDS_IN_A_DAY } diff --git a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/serializers/DateToTimestampSerializer.kt b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/serializers/DateToTimestampSerializer.kt index bc4c2f45..51a54745 100644 --- a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/serializers/DateToTimestampSerializer.kt +++ b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/serializers/DateToTimestampSerializer.kt @@ -38,7 +38,7 @@ internal object DateToTimestampSerializer : JsonTransformingSerializer(Lon } val localDateTime = LocalDateTime.parse(dateString, formatter) - val timestamp = localDateTime.toInstant(TimeZone.UTC).toEpochMilliseconds() + val timestamp = localDateTime.toInstant(TimeZone.UTC).epochSeconds return runCatching { JsonPrimitive(timestamp) }.getOrDefault(element) }