Git Product home page Git Product logo

time's Issues

Operator extension functions do not support time intervals longer than Int.MAX_VALUE

Reproduction steps

  1. Create a time interval for years:
class Year : TimeUnit {
    override val timeIntervalRatio = 31_556_952.0
}

val Number.years: Interval<Year>
	get() = Interval(this)
  1. Create a Calendar instance and add 1 year:
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
}

Artifacts on bintray

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.

Using 3.5.0 (gradle-5.4.1), you must import time lib too, not just time-android

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

Add a toString method and ability to get value and units

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.