ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - hankdavidson/ktime: kotlin extensions to the java8 time library
kotlin extensions to the java8 time library. Contribute to hankdavidson/ktime development by creating an account on GitHub.
Visit Site

GitHub - hankdavidson/ktime: kotlin extensions to the java8 time library

GitHub - hankdavidson/ktime: kotlin extensions to the java8 time library

ktime

Kotlin extensions to the java8 time library

Examples

Conversion from numbers to Duration

Int, Long and Double values can be suffixed with a time unit to create a Duration

val delay = 30.seconds              // equal to Duration.ofSeconds(30)
val longDelay = 2.5.minutes         // equal to Duration.ofSeconds(150)

Available Duration suffixes: nanos, micros, millis, seconds, minutes, hours

Conversion from numbers to Period

Int and Long values can be suffixed with a date unit to create a Period

val interval = 30L.days

Available Period suffixes: days, weeks, months, years

Mathematical operations on Duration and Period

addition, subtraction, negation

val duration = 2.hours + 30.minutes
val period = 2.months + 14.days            
val duration = 1.hours - 1.minutes
val negativeDuration = -30.seconds

Scaling

val fullDuration = 2.5.hours
val doubledDuration = 2.5.hours * 2
val halfDuration = 2.5.hours / 2

Comparisons on Duration

Note that Period is not Comparable

1.hours > 1.minutes
1000.nanos == 1.micros    

Destructuring

val (sec, nano) = 2.5.seconds
val (y, m, d) = 1.years + 2.months + 3.days

Offsets from now

These produce an OffsetDateTime with a UTC offset:

val lastHour = 1.hours.ago
val thisTimeTomorrow = 1.days.fromNow

Operations on times and dates

Add or subtract Duration or Period from date/time types

val startTime = 30.seconds.fromNow
val stopTime = startTime + 1.minutes                                 // add Durations & Periods to dates & times

TemporalQueries

Most TemporalQueries involve extracting a data type that contains a subset of the data for the current data type. For example, you can go from OffsetDateTime to LocalDateTime, but not vice-versa because LocalDateTime doesn't have zoneOffset.

val thisYear: Year = 0.seconds.ago.year
val thisMonth: Month = 0.seconds.ago.month
val dayOfWeek: DayOfWeek = 0.seconds.ago.dayOfWeek
val currentTime: localTime = 0.seconds.ago.localTime

TemporalAdjusters

val startOfThisMonth = 0.seconds.ago.atStartOfThisMonth
val startOfNextMonth = 0.seconds.ago.atStartOfNextMonth
val endOfThisMonth = 0.seconds.ago.atEndOfThisMonth
val startOfThisYear = 0.seconds.ago.atStartOfThisYear
val startOfNextYear = 0.seconds.ago.atStartOfNextYear
val endOfThisYear = 0.seconds.ago.atEndOfThisYear

Temporal Ranges

Although java 8's time library doesn't support the idea of a Range, this library does. In addition to offering a step modifier, these ranges also offer a unit modifier. The unit modifier is used to specify the unit (MINUTES, DAYS, etc.) to use if you iterate over the range. If no unit is specified, the native precision is used (e.g. the native precision for a date is DAYS, the native precision for DateTimes is NANOS)

Inclusive ranges

 (2010.asYear..2020.asYear).count() // should be equal to 11

 val inOfferPeriod = 0.seconds.ago in offer.start..offer.end
 
 for (d in date1..date2) {...}
 for (d in time1..time2 step 10 unit MINUTES) {...}
 for (d in dateTime1..dateTime2 unit DAYS) {...}

Exclusive ranges

 (2010.asYear until 2020.asYear).count() // should be equal to 10
 for (d in date1 until date2) {...}
 for (d in time1 until time2 step 10 unit MINUTES) {...}
 for (d in dateTime1 until dateTime2 unit DAYS) {...}

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory