Commit Graph

56 Commits

Author SHA1 Message Date
Ilya Gorbunov e35ace5d3a Deprecate AbstractDoubleTimeSource
There are too few usages of it, and it can be mostly replaced with AbstractLongTimeSource.
2022-09-19 19:16:40 +00:00
Ilya Gorbunov 57c9d61291 ComparableTimeMark and specialized TimeSource KT-54082
- Introduce ComparableTimeMark interface extending TimeMark,
and TimeSource.WithComparableMarks - a time source that returns such time marks.
- Implement ComparableTimeMark in ValueTimeMark and AbstractLong/DoubleTimeMark classes.
2022-09-19 19:16:40 +00:00
Ilya Gorbunov 4e31f368d5 Add more info to a flaky assertion, increase wait duration 2022-07-19 20:57:39 +00:00
Ilya Gorbunov 3a029b8e80 Fix ValueTimeMark adjustment in rare cases and properly test it 2022-07-01 15:20:22 +00:00
Vsevolod Tolstopyatov 0c8b31b9ed Clarify specification of Duration.parseIsoString
KT-52778


Co-authored-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>

Merge-request: KT-MR-6556
Merged-by: Vsevolod Tolstopyatov <vsevolod.tolstopyatov@jetbrains.com>
2022-06-28 07:43:33 +00:00
Ilya Gorbunov 77cf41c189 Saturate overflowing values when adjusting time marks
KT-46132
2022-04-14 16:54:31 +00:00
Ilya Gorbunov fede70d0d5 Make TimeMark returned by TimeSource.Monotonic a value class
This value class wraps Long on JVM and Native thus reducing allocations
in time measurement scenarios when the default monotonic time source is
statically known.

KT-46132
2022-04-14 16:54:30 +00:00
Ilya Gorbunov 04d70162d2 Make DurationUnit not a typealias of TimeUnit on JVM
Provide conversion functions between DurationUnit and TimeUnit
2021-09-30 14:31:54 +00:00
Ilya Gorbunov 21a9198fff Bring back Duration construction extensions KT-46229
Return the extension properties for constructing Duration from numbers,
but this time place them in Duration.Companion rather than on top-level.

- provide the new set of construction extension properties
  in companion of Duration
- leave top-level extension properties experimental,
  increase their deprecation level to ERROR,
  propose the extension properties in companion instead.
- leave Duration companion static factory functions experimental,
  deprecate them and propose the extension properties in companion instead.
2021-09-24 16:17:53 +00:00
Ilya Gorbunov 96611de344 Stabilize Duration, DurationUnit and related top-level functions KT-46784
Co-authored-by: Abduqodiri Qurbonzoda <abduqodiri.qurbonzoda@jetbrains.com>
2021-09-24 16:17:53 +00:00
Ilya Gorbunov fbc43cbebe Duration.toComponents: change the highest component type to Long 2021-09-02 02:44:16 +00:00
Ilya Gorbunov 5072653957 Duration: parse explicit positive values parenthesized 2021-07-12 04:39:28 +00:00
Ilya Gorbunov 682cb8e34a Duration default toString: use 0, 1, 2, 3, 6, or 9 decimal digits
KT-42851
2021-07-12 04:39:27 +00:00
Ilya Gorbunov 0427eec20f Quote invalid strings in exception messages 2021-07-12 04:39:26 +00:00
Ilya Gorbunov 3f6e2be687 Duration: do not use scientific format for large values
The largest duration value formatted in ns with maximal decimals
would fit in 40 chars.
2021-07-12 04:39:25 +00:00
Ilya Gorbunov 1be1e5279c Duration: parse and format negative values parenthesized 2021-07-12 04:39:25 +00:00
Ilya Gorbunov ca1a9e4ca3 Duration: longer than long values in ISO components, test negative cases 2021-07-12 04:39:24 +00:00
Ilya Gorbunov 1c6ab08220 Introduce functions to parse a duration from a string KT-45325 2021-07-12 04:39:23 +00:00
Ilya Gorbunov 7ab6f6c9b2 Change Duration.INFINITE.toIsoString representation 2021-07-12 04:39:23 +00:00
Ilya Gorbunov ae3d9cc3cd Small durations are formatted with sub-second units KT-42851 2021-07-12 04:39:22 +00:00
Ilya Gorbunov 150ce812f1 Use days component in the default duration format KT-42851 2021-07-12 04:39:21 +00:00
Ilya Gorbunov 255c4b405e Duration: round Double value to Long ns instead of truncating it KT-47675 2021-07-12 04:39:21 +00:00
Ilya Gorbunov 42cd2e65e6 Change Duration.toString format KT-42851 2021-07-12 04:39:20 +00:00
Ilya Gorbunov 0e93924ff3 Duration: inWholeUnits properties instead of inUnits
Introduce conversion properties returning Long values,
deprecate the old ones returning Doubles.
2021-04-02 17:44:10 +03:00
Ilya Gorbunov 11d15f3343 Make Duration storage ranges symmetric and non-overlapping
Increase accuracy of multiplication and division.
2021-04-02 17:44:10 +03:00
Ilya Gorbunov 4fd2254f3f Advance TestTimeSource more precisely
Change durations in its test so that they hold precise number
of nanoseconds
2021-04-02 17:44:08 +03:00
Ilya Gorbunov fa7460ba48 Store Duration value as a multi-range Long
Now precision loss happens at bigger durations.

This changes the binary API due different underlying type of Duration.
2021-04-02 17:43:20 +03:00
Ilya Gorbunov a7fda66fa1 Suggest duration static factories instead of number extension properties
Introduce Duration companion functions to convert numbers to Duration.
Deprecate number extension properties and propose to use these
new functions instead.
2021-03-10 13:23:32 +03:00
Ilya Gorbunov 3c37bbaf64 Duration: normalize to avoid negative zeroes (KT-44168)
The current comparison method of inline classes makes
durations of positive and negative zeroes non-equal.
To avoid that, normalize the duration value upon construction
preventing negative zero being stored.
2020-12-31 19:44:39 +03:00
Ilya Gorbunov ae6f10df3b Duration: reject NaN duration values (KT-44168) 2020-12-31 19:44:10 +03:00
Svyatoslav Scherbina 0f4173cdfa Fix running stdlib tests in worker on Native
Add `@SharedImmutable` or `@ThreadLocal` where required.
2020-12-14 19:03:06 +03:00
Alexander Udalov 795d6ab407 Migrate UseExperimental->OptIn in project sources 2020-03-10 12:07:14 +01:00
Ilya Gorbunov 1336da8453 Rename Clock to TimeSource, ClockMark to TimeMark
Step 2: rename classes and interfaces.
Provide deprecated typealiases to smooth migration.
2020-01-21 03:28:35 +03:00
Ilya Gorbunov a985402507 Introduce ClockMark.hasPassedNow, hasNotPassedNow functions
Makes it more clear to use them than comparing elapsed with Duration.ZERO.
2019-08-16 15:29:16 +03:00
Ilya Gorbunov 44195d436e Rename: Clock.markNow, ClockMark.elapsedNow
Add "Now" suffix to the names of functions that depend on the current
time moment.
2019-08-16 15:29:16 +03:00
Ilya Gorbunov f889d25287 Introduce TestClock.plusAssign(Duration) and hide implementation details
TestClock.plusAssign(Duration) is for advancing TestClock time.
Hide reading value, do not allow to provide initial reading,
fix clock unit to nanoseconds at construction time.
2019-08-16 15:28:45 +03:00
Ilya Gorbunov 4de9361c37 Introduce Duration.isPositive method 2019-08-16 15:25:57 +03:00
Ilya Gorbunov d7252548fc Add symmetric number * duration operators 2019-06-18 19:49:50 +03:00
Ilya Gorbunov a2b1c537af Change Duration.toString scientific exponent formatting
- use 'e+' for positive exponents in scientific format
2019-06-18 19:49:35 +03:00
Ilya Gorbunov a5b7c270ae Change Duration.toString(unit, decimals) formatting
- switch to scientific notation when value is too big (greater than 1e14)
- allow at most 12 decimals, larger values are coerced to 12
- use scientific format with exactly two decimals in mantissa in JVM
2019-06-18 19:49:35 +03:00
Ilya Gorbunov c66740a7ed Explicit public visibility, SinceKotlin and ExperimentalTime status
Use file level ExperimentalTime opt-in in tests.
2019-06-18 04:02:35 +03:00
Ilya Gorbunov 3b989cc815 Avoid using 'D' component in ISO duration string representation
Days in ISO have nominal duration, they are not always equal to 24H
2019-06-18 04:02:34 +03:00
Ilya Gorbunov 368452748b Move convertDurationUnit into Duration companion 2019-06-18 04:02:33 +03:00
Ilya Gorbunov ca10d13f34 Rename Duration storage property to 'value' 2019-06-18 04:02:33 +03:00
Ilya Gorbunov 365cbb94cd Change Duration.absoluteValue to property 2019-06-18 04:02:33 +03:00
Ilya Gorbunov 3f7a0d0845 Rename DurationMeasured to TimedValue, withMeasureTime to measuredTimeValue
Add measureTime docs
2019-06-18 04:02:33 +03:00
Ilya Gorbunov 9deac2a591 Rename withComponents to toComponents and add two overloads of them 2019-06-18 04:02:33 +03:00
Ilya Gorbunov 796ad29637 Add shortcuts to convert duration to milliseconds and nanoseconds 2019-06-18 04:02:32 +03:00
Ilya Gorbunov 8004c34e44 Reduce Duration API surface, add top-level docs
- toDuration(unit) extension instead of constructors
- toDouble/Long/Int(unit) function instead of inUnits()
- remove static factory functions
- remove MIN_VALUE/MAX_VALUE constants
2019-06-18 04:02:32 +03:00
Ilya Gorbunov 682430766b Add ClockMark and measureTime tests with test clock 2019-06-18 04:02:32 +03:00