Skip to content
This repository was archived by the owner on Jan 22, 2023. It is now read-only.

Commit cb9de9d

Browse files
author
Jonas Schubert
committed
Merge branch 'develop'
2 parents 3f16165 + 69d0990 commit cb9de9d

File tree

36 files changed

+607
-498
lines changed

36 files changed

+607
-498
lines changed

README.md

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,59 @@
55
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
66
<a target="_blank" href="https://www.paypal.me/GuepardoApps" title="Donate using PayPal"><img src="https://img.shields.io/badge/paypal-donate-blue.svg" /></a>
77

8-
[![Build](https://img.shields.io/badge/build-success-green.svg)](https://github.com/TimeXt/TimeXt-Kotlin/blob/master/releases/lib-2018-10-20-1.aar)
9-
[![Version](https://img.shields.io/badge/version-v0.1.0.181020-blue.svg)](https://github.com/TimeXt/TimeXt-Kotlin/tree/master/releases/)
8+
[![Build](https://img.shields.io/badge/build-success-green.svg)](https://github.com/TimeXt/TimeXt-Kotlin/blob/master/releases/lib-2018-10-28-1.aar)
9+
[![Version](https://img.shields.io/badge/version-v0.2.0.181028-blue.svg)](https://github.com/TimeXt/TimeXt-Kotlin/tree/master/releases/)
10+
[![CodeCoverage](https://img.shields.io/badge/codeCoverage-71-orange.svg)](https://github.com/TimeXt/TimeXt-Kotlin/tree/master/)
1011

1112
First of all many thanks to [Kizitonwose](https://github.com/kizitonwose/Time) for the original idea and already awesome library!
1213

13-
This library shall help to reduce code like
14+
This library shall help to reduce code like...
1415

1516
```kotlin
1617
val dayInMillis = 24 * 60 * 60 * 1000 // Represent a day in milliSeconds
18+
19+
```
20+
21+
... or allow code like
22+
23+
```kotlin
24+
val date1 = java.sql.Date(1540719288642)
25+
val date2 = java.sql.Date(1540722888642)
26+
27+
val difference = date2 - date1
28+
1729
```
1830

1931
## How to use
2032

2133
### Basics
2234

2335
```kotlin
24-
val oneWeek = 1.weeks // Type is Interval<Week>
25-
val threeDays = 3.days // Type is Interval<Day>
26-
val elevenHours = 11.hours // Type is Interval<Hour>
27-
val sixMinutes = 6.minutes // Type is Interval<Minute>
28-
val fiftySeconds = 50.seconds // Type is Interval<Second>
29-
val hundredMilliSeconds = 100.milliSeconds // Type is Interval<MilliSecond>
30-
val fiveMicroSeconds = 5.microSeconds // Type is Interval<MicroSecond>
31-
val oneNanoSecond = 1.nanoSeconds // Type is Interval<NanoSecond>
32-
val onePicoSecond = 1.picoSeconds // Type is Interval<PicoSecond>
33-
34-
val oneDayInMillis = 1.days.inMilliSeconds // Converts one day into milliseconds
35-
val twoWeeksInHours = 2.weeks.inHours // Converts two weeks into hours
36-
37-
val duration = 1.days + 11.hours + 35.minutes + 15.seconds - 250.milliSeconds
36+
// Type is TimeXt
37+
val oneWeek = 1.weeks
38+
val threeDays = 3.days
39+
val elevenHours = 11.hours
40+
val sixMinutes = 6.minutes
41+
val fiftySeconds = 50.seconds
42+
val hundredMilliseconds = 100.milliseconds
43+
44+
val oneDayInMillis = 1.days.inMilliSeconds // Returns one day in milliseconds
45+
val twoWeeksInHours = 2.weeks.inHours // Returns two weeks in hours
46+
47+
// Converts the existing 3h-Class into a 180min-Class
48+
val threeHoursToMinutes = 3.hours.toMinutes()
49+
// 3.hours === TimeXt(3, TimeXtUnit.hour)
50+
// 180.minutes === TimeXt(180, TimeXtUnit.minute)
51+
52+
val duration = 1.days + 11.hours + 35.minutes + 15.seconds - 250.milliseconds
3853
val multipliedDuration = 1.5 * duration
3954
val dividedDuration = duration / 2
4055

4156
val isLessTrue = 1.days < 1.weeks // True
4257
val isLessFalse = 24.hours < 360.minutes // False
4358

4459
val isBiggerTrue = 5.minutes > 30.seconds // True
45-
val isBiggerFalse = 500.nanoSeconds > 1.minutes // False
60+
val isBiggerFalse = 500.minutes > 5.weeks // False
4661

4762
```
4863

@@ -52,16 +67,19 @@ val isBiggerFalse = 500.nanoSeconds > 1.minutes // False
5267
// Calendar
5368
val inOneHour = Calendar.getInstance() + 1.hours
5469
val threeDaysAgo = Calendar.getInstance() - 3.days
70+
val difference = calendar1 - calendar2 // you can perform minus on calendar and get a TimeXt-object
5571

5672
// Sql Date
57-
val sqlDate: java.sql.Date = java.sql.Date()
58-
sqlDate + 5.minutes
59-
sqlDate - 30.seconds
73+
var sqlDate: java.sql.Date = java.sql.Date()
74+
sqlDate = sqlDate + 5.minutes
75+
sqlDate = sqlDate - 30.seconds
76+
val difference = sqlDate1 - sqlDate2 // you can perform minus on java.sql.Date and get a TimeXt-object
6077

6178
// Util Date
6279
val utilDate: java.util.Date = java.util.Date()
63-
utilDate + 5.minutes
64-
utilDate - 30.seconds
80+
utilDate = utilDate + 5.minutes
81+
utilDate = utilDate - 30.seconds
82+
val difference = utilDate1 - utilDate2 // you can perform minus on java.util.Date and get a TimeXt-object
6583

6684
// Timer
6785
val timer = Timer()
@@ -70,7 +88,7 @@ timer.schedule(10.seconds) {
7088
}
7189
```
7290

73-
The library also includes extensions for Android's Handler class, this is only available if you compile the "lib-android" module.
91+
The library also includes extensions for Android's Handler class, this is only available if you compile the "timext-android" module.
7492

7593
```kotlin
7694
val handler = Handler()
@@ -79,27 +97,29 @@ handler.postDelayed({
7997
}, 2.minutes)
8098
```
8199

82-
### Custom IDateTimeUnit
100+
### Custom TimeXtUnit
83101

84-
If you would like to have your own date time unit, implement it as followed:
102+
If you would like to have your own timext unit, implement it as followed:
85103

86104
```kotlin
87-
class Year : IDateTimeUnit {
88-
// amount of seconds in one year
89-
override val dateTimeIntervalRatio = 365.0 * 24.0 * 60.0 * 60.0
90-
}
105+
val year: Double = 365 * 24 * 60 * 60 * 1e3
91106

92107
// Add also some extensions:
93-
val Number.years: Interval<Year>
94-
get() = Interval(this)
108+
val Number.years: TimeXt
109+
get() = TimeXt(this.toDouble(), year)
95110

96-
val Interval<IDateTimeUnit>.inYears: Interval<Year>
97-
get() = converted()
111+
val TimeXt.inYears: TimeXt
112+
get() = this.value * this.unit / year
113+
114+
fun toYears(): TimeXt {
115+
return TimeXt(this.inYears, year)
116+
}
98117

99118
// Use it like:
100-
val threeYears = Interval<Year>(3)
119+
val threeYears = TimeXt(3, year)
101120
val oneYear = 1.years
102121
val daysInYear = 365.days.inYears
122+
val yearsFromDays = 365.days.toYears()
103123

104124
```
105125

build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
buildscript {
22
ext.gradle_version = '3.2.1'
3+
ext.jacoco_coverage_version = '0.4.0'
34
ext.junit_version = '4.12'
45
ext.kotlin_version = '1.2.71'
6+
ext.maven_gradle_version = '2.0'
57

68
repositories {
79
google()
810
jcenter()
911
}
12+
1013
dependencies {
1114
classpath "com.android.tools.build:gradle:$gradle_version"
1215
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
16+
classpath "com.github.dcendents:android-maven-gradle-plugin:$maven_gradle_version"
17+
classpath "com.palantir:jacoco-coverage:$jacoco_coverage_version"
1318
}
1419
}
1520

@@ -18,4 +23,6 @@ allprojects {
1823
google()
1924
jcenter()
2025
}
21-
}
26+
}
27+
28+
apply plugin: 'com.palantir.jacoco-full-report'

lib-android/src/main/kotlin/guepardoapps/timext/kotlin/extensions/HandlerExtensions.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/src/main/kotlin/guepardoapps/timext/kotlin/DateTimeUnitCollection.kt

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/src/main/kotlin/guepardoapps/timext/kotlin/IDateTimeUnit.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/src/main/kotlin/guepardoapps/timext/kotlin/Interval.kt

Lines changed: 0 additions & 79 deletions
This file was deleted.

lib/src/main/kotlin/guepardoapps/timext/kotlin/extensions/CalendarExtensions.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/src/main/kotlin/guepardoapps/timext/kotlin/extensions/DateTimeExtensions.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

lib/src/main/kotlin/guepardoapps/timext/kotlin/extensions/NumberExtensions.kt

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)