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

commonMain.com.batoulapps.adhan2.data.DateComponents.kt Maven / Gradle / Ivy

There is a newer version: 0.0.5
Show newest version
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