Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hotchemi/khronos
An intuitive Date extensions in Kotlin.
https://github.com/hotchemi/khronos
Last synced: 2 days ago
JSON representation
An intuitive Date extensions in Kotlin.
- Host: GitHub
- URL: https://github.com/hotchemi/khronos
- Owner: hotchemi
- License: apache-2.0
- Created: 2016-03-20T19:02:15.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-11T05:10:27.000Z (over 4 years ago)
- Last Synced: 2024-10-26T21:32:54.836Z (16 days ago)
- Language: Kotlin
- Homepage: http://hotchemi.github.io/khronos
- Size: 560 KB
- Stars: 327
- Watchers: 8
- Forks: 18
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kotlin-cn - khronos - An intuitive Date extensions in Kotlin. (开源库和框架 / 其他)
- awesome - khronos - An intuitive Date extensions in Kotlin. (etc)
- awesome - khronos - An intuitive Date extensions in Kotlin. (etc)
README
# khronos
![Build Status](https://github.com/hotchemi/khronos/workflows/build/badge.svg) [![Download](https://api.bintray.com/packages/hotchemi/maven/khronos/images/download.svg) ](https://bintray.com/hotchemi/maven/khronos/_latestVersion) [![License](https://img.shields.io/badge/license-APACHE2-green.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
An intuitive Date extensions in Kotlin.
## Usage
### Add durations to date
```kotlin
val today = Dates.today
val nextWeek = today + 1.week
val dayBeforeYesterday = today - 2.days// shortcuts #1
val tomorrow = Dates.tomorrow
val yesterday = Dates.yesterday// shortcuts #2
val yesterday = 1.days.ago
val fiveYearsSince = 5.years.since
```### Initialize by specifying date components
```kotlin
val birthday = Dates.of(year = 1990, month = 1, day = 21)
val firstCommitDate = Dates.of(year = 2016, month = 2, day = 26, hour = 18, minute = 58, second = 31, millisecond = 777)
```### Initialize by changing date components
```kotlin
val today = Dates.today
val christmas = today.with(month = 12, day = 25)
val thisSunday = today.with(weekday = 1)// shortcuts
val newYearDay = today.beginningOfYear
val newYearsEve = today.endOfYear
```### Check day of the week
```kotlin
Dates.today.isFriday() // false
```### Format and parse
```kotlin
5.minutes.since.toString("yyyy-MM-dd HH:mm:ss")
//=> "2015-03-01 12:05:00""1987-06-02".toDate("yyyy-MM-dd")
//=> Dates.of(year = 1987, month = 6, day = 2)
```### Compare dates
```kotlin
1.day.ago > 2.days.ago // true
1.day.ago in 2.days.ago..Dates.today // true
```## Install
`${latest.version}` = [![Download](https://api.bintray.com/packages/hotchemi/maven/khronos/images/download.svg) ](https://bintray.com/hotchemi/maven/khronos/_latestVersion)
```groovy
dependencies {
compile 'com.github.hotchemi:khronos:${latest.version}'
}
```## Notice
- khronos is definitely inspired by [naoty/Timepiece(Swift)](https://github.com/naoty/Timepiece).
## Licence
```
Copyright 2016 Shintaro KatafuchiLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```