Giter Site home page Giter Site logo

kompat-time's Introduction

kompat-time

A Kotlin compatibility layer for constructing and manipulating Java Time.

Download

Compatibility

kompat-time is built on the Java Time API defined in JSR-310 and implemented in Java 8. Therefore it should only be used on JVM's with Java >= 8. Sorry no Android or JS targeting.

Builders

import nz.ahw.kompat.time.*
import nz.ahw.kompat.time.units.*

val ld: LocalDate = LocalDate(2017, Month.DECEMBER, 8) // 2017/12/08
val lt: LocalTime = LocalTime(16, 40) // 16:40
val ldt: LocalDateTime = LocalDateTime(ld, lt) // 2017-12-08T16:40

val p: Period = Period(2.years) // P2Y
val d: Duration = Duration(4.hours) // PT4H

val t: Instant = Instant(150.seconds) // 1970-01-01T00:02:30Z

Extensions

// Arithmetic operations 
val p2: Period = p + 4.months - 3.days // P2Y4M-3D
val d2: Duration = d + 10.minutes // PT4H10M

val ld2: LocalDate = ld + 2.days // 2017/12/10

// Infix Functions
val ldt2: LocalDateTime = ld atTime lt // 2017-12-08T16:40


// With Functions
val ld3: LocalDate = ld.with(month = Month.OCTOBER)

Date Literals

import knz.ahw.kompat.time.literal.dates.*

// DMY (Little Endian)
val date: LocalDate = 8/Nov/2017

// MDY (Middle Endian)
val date: LocalDate = Nov/8/2017

// YMD (Big Endian)
val date: LocalDate = 2017-Nov-8

Maven

Configure to use the kompat repository

<repository>
    <id>bintray-ahwnz-kompat</id>
    <name>bintray-kompat</name>
    <url>https://dl.bintray.com/ahwnz/kompat</url>
</repository>

Add the dependency

<dependency>
    <groupId>nz.ahwnz.kompat</groupId>
    <artifactId>kompat-time</artifactId>
    <version>{version}</version>
</dependency>

kompat-time's People

Contributors

alexwestphal avatar

Watchers

 avatar  avatar

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.