All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.paoapps.fifi.domain.LocalTime.kt Maven / Gradle / Ivy

Go to download

Kotlin Multiplatform Mobile framework for optimal code sharing between iOS and Android.

The newest version!
import kotlinx.datetime.LocalTime

//package com.paoapps.fifi.domain
//
//import com.paoapps.fifi.serialization.LocalTimeSerializer
//import kotlinx.serialization.KSerializer
//import kotlinx.serialization.Serializable
//import kotlinx.serialization.descriptors.PrimitiveKind
//import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
//import kotlinx.serialization.encoding.Decoder
//import kotlinx.serialization.encoding.Encoder
//
//
//@Serializable(with = LocalTimeSerializer::class)
//data class LocalTime(val hour: Int, val minute: Int): Comparable {
//
//    private val minutesSinceMidnight get() = hour * 60 + minute
//
//    fun format(): String {
//        var hours = "${hour}"
//        if (hour < 10) {
//            hours = "0$hours"
//        }
//
//        var minutes = "${minute}"
//        if (minute < 10) {
//            minutes = "0$minutes"
//        }
//
//        return "$hours:$minutes"
//    }
//
//    companion object {
//        fun parse(value: String): LocalTime {
//            val parts = value.split(":").map { it.toInt() }
//            if (parts.size != 2) {
//                throw IllegalArgumentException("Invalid time $value")
//            }
//
//            return LocalTime(parts[0], parts[1])
//        }
//    }
//
//    override fun compareTo(other: LocalTime) = minutesSinceMidnight.compareTo(other.minutesSinceMidnight)
//}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy