An intuitive Date extensions in Kotlin.
Kotlin
Latest commit 0720b1e Mar 24, 2016 @hotchemi Delete unused import.
Permalink
Failed to load latest commit information.
gradle/wrapper First commit. Mar 22, 2016
src Delete unused import. Mar 24, 2016
.gitignore First commit. Mar 22, 2016
.travis.yml Add timezone for travis. Mar 24, 2016
LICENSE First commit. Mar 22, 2016
README.md Delete unused import. Mar 24, 2016
build.gradle First commit. Mar 22, 2016
gradle.properties Prepare for 0.1.0. Mar 23, 2016
gradlew First commit. Mar 22, 2016
gradlew.bat First commit. Mar 22, 2016
settings.gradle First commit. Mar 22, 2016

README.md

khronos

Build Status Download License

An intuitive Date extensions in Kotlin.

Usage

Add durations to date

val now = Dates.now
val nextWeek = now + 1.week
val dayBeforeYesterday = now - 2.days

// shortcuts #1
val today = Dates.today
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

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)

Initialize by changing date components

val now = Dates.now
val christmas = now.with(month = 12, day = 25)
val thisSunday = now.with(weekday = 1)

// shortcuts
val newYearDay = now.beginningOfYear
val newYearsEve = now.endOfYear

Check day of the week

Dates.now.isFriday() // false

Format and parse

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

1.day.ago > 2.days.ago // true
1.day.ago in 2.days.ago..Dates.now // true

Install

${latest.version} = Download

dependencies {
  compile 'com.github.hotchemi:khronos:${latest.version}'
}

Notice

  • khronos doesn't support timezone yet so please don't use it in production.
    • I'll fix it ASAP.
  • khronos is definitely inspired by naoty/Timepiece(Swift).

Licence

Copyright 2016 Shintaro Katafuchi

Licensed 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 at

   http://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.