commonMain.com.batoulapps.adhan2.data.DateComponents.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of adhan2 Show documentation
Show all versions of adhan2 Show documentation
A high precision Islamic prayer times library
package com.batoulapps.adhan2.data
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
class DateComponents(val year: Int, val month: Int, val day: Int) {
companion object {
/**
* Convenience method that returns a DateComponents from a given [Instant]
* @param instant the current instant
* @return the [DateComponents] (according to the default device timezone)
*/
fun from(instant: Instant): DateComponents {
val localDateTime = instant.toLocalDateTime(TimeZone.currentSystemDefault())
return fromLocalDateTime(localDateTime)
}
/**
* Convenience method that returns a DateComponents from a given [LocalDateTime]
* @param date the date
* @return the DateComponents
*/
fun fromLocalDateTime(date: LocalDateTime): DateComponents {
return DateComponents(date.year, date.monthNumber, date.dayOfMonth)
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy