kizitonwose / time Goto Github PK
View Code? Open in Web Editor NEWType-safe time calculations in Kotlin, powered by generics.
License: MIT License
Type-safe time calculations in Kotlin, powered by generics.
License: MIT License
Reproduction steps
class Year : TimeUnit {
override val timeIntervalRatio = 31_556_952.0
}
val Number.years: Interval<Year>
get() = Interval(this)
val cal = Calendar.getInstance() + 1.years
Expected behavior
The calendar instance adds 1 year to the current time.
Actual behavior
1 year is not added to the calendar instance.
If you change the following extensions functions to use timeInMillis
instead of converting the long to an int and using Calendar#add
it would fix the intended behavior for time intervals over Int.MAX_VALUE
:
operator fun Calendar.plus(other: Interval<TimeUnit>): Calendar = (clone() as Calendar).apply {
timeInMillis += other.inMilliseconds.longValue
}
operator fun Calendar.minus(other: Interval<TimeUnit>): Calendar = (clone() as Calendar).apply {
timeInMillis -= other.inMilliseconds.longValue
}
Any chance of the artifacts being uploaded to bintray rather than using jitpack. This is definitely preferred for commercial projects as well as generally being more stable.
Just updated an older project where I was using this library to Android Gradle Plugin 3.5.0 ( gradle wrapper dist gradle-5.4.1 ).
Initially I was just using implementation 'com.github.kizitonwose.time:time-android:1.0.2'
as instructed in the readme, and it was working.
After update, there were many errors ( e.g. extension functions on Int like .seconds were on red - not found ). Weirdly the time:1.0.2
classes somehow aren't in classpath anymore .
The workaround solution was to add time:1.0.2
as direct dependency of the project, but it should be checked what did 3.5.0 break.
I'll give it a shot on fixing and make a PR when I have some free time
So TimeUnit should have a toString that returns a string like "days" or "minutes"
Interval should have a toString that returns a string like "15 seconds"
Interval should have properties for the actual value and TimeUnit:
val a = 15.minutes
val b = a.value // == 15
val c = a.unit // == Minute
val d = a.unit.toString() // == "15 minutes"
This is more for debugging/logging purposes than application output so internationalization is not an issue
Add support for adding intervals to classes like LocalDate. Might want to do it as a separate library and might want to also do it for the 310 backport as well
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.