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

feat: Replace timestamp millis to timestamp seconds & add java date extension for Android #83

Merged
merged 2 commits into from
Nov 8, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.multiplatform_swisstransfer.common.ext

import java.util.Date

fun Long.toDateFromSeconds() = Date(this * 1000)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ data class TransferUi(
val files: List<FileUi>,
) {

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal object DateToTimestampSerializer : JsonTransformingSerializer<Long>(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)
}
Expand Down
Loading