Asimov-time-kt - Useful time and date related functions and extensions

Overview

Maven License: MIT CI Status

asimov/time

Useful time and date related functions and extensions.

Installation

Gradle (Kotlin)

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.nbottarini:asimov-time:0.5.1")
}

Gradle (Groovy)

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.nbottarini:asimov-time:0.5.1'
}

Maven

<dependency>
    <groupId>com.nbottarini</groupId>
    <artifactId>asimov-time</artifactId>
    <version>0.5.1</version>
</dependency>

Usage

Extensions

    yearMonth.formatAsISO8601() // Formats a year month in ISO-8601. Ex: 2020-06
    localDate.formatAsISO8601() // Formats date in ISO-8601. Ex: 2020-06-09
    localDateTime.formatAsISO8601() // Formats date time in ISO-8601. Ex: 2020-06-09T22:10:05Z

Parsers

    LocalDateParser().parseISO8601("2020-06-09") // returns LocalDate
    LocalDateParser().parse("09/06/2020", "d/M/yyyy") // returns LocalDate
    
    LocalDateTimeParser().parseISO8601("2020-06-09T22:10:05Z") // returns LocalDateTime
    LocalDateTimeParser().parseISO8601("2020-06-09T22:10:05-03:00") // returns LocalDateTime in UTC
    LocalDateTimeParser().parseISO8601("2020-06-09T22:10:05-03:00", ZoneOffset.UTC) // returns LocalDateTime in UTC

    YearMonthParser().parseISO8601("2020-06") // returns YearMonth

Clock

Provides a central clock to use in your code. The clock can be stopped to control time in tests.

    Clock.now() // returns LocalDateTime with current date and time in UTC
    Clock.today() // returns LocalDate with current date
    Clock.stoppedAt(someDate) // Stops clock at given date with time 00:00:00
    Clock.stoppedAt(someDateTime) // Stops clock at given time
    Clock.live() // Sets the clock to have live time again

It also comes with a timed function to use in tests. The timed function receives and executes a lambda. It stops the clock and makes it advance 1 second with each call. This function helps to make tests that depends on time to be deterministic.

    timed { someAction() }
    timed { someOtherAction() } // Time passes on each call
You might also like...
Standalone Android widget for picking a single date from a calendar view.
Standalone Android widget for picking a single date from a calendar view.

TimesSquare for Android Standalone Android widget for picking a single date from a calendar view. Usage Include CalendarPickerView in your layout XML.

Joda-Time library with Android specialization

Android has built-in date and time handling - why bother with a library? If you've worked with Java's Date and Calendar classes you can probably answer this question yourself, but if not, check out Joda-Time's list of benefits.

Estimated Time of Arrival Bar
Estimated Time of Arrival Bar

Estimated Time of Arrival Bar

Android calendar view inspired by Sunrise calendar and iOS7 stock calendar
Android calendar view inspired by Sunrise calendar and iOS7 stock calendar

SilkCal Android calendar view inspired by Sunrise calendar and iOS7 stock calendar. Usage Add compile 'me.nlmartian.silkcal:library:0.1.1' to your dep

📅 CosmoCalendar is a fully customizable calendar with a wide variety of features and displaying modes.
📅 CosmoCalendar is a fully customizable calendar with a wide variety of features and displaying modes.

CosmoCalendar Made by Applikey Solutions Usage Customization Common Selection Current day Navigation buttons Weekend days Connected days Disabled days

CustomizableCalendar is a library that allows you to create your calendar, customizing UI and behaviour
CustomizableCalendar is a library that allows you to create your calendar, customizing UI and behaviour

CustomizableCalendar This library allows you to create a completely customizable calendar. You can use CustomizableCalendar to create your calendar, c

A simple library which gives you custom design CalendarView with dialog functionality and event handlers.
A simple library which gives you custom design CalendarView with dialog functionality and event handlers.

CalendarView A simple library which gives you custom design CalendarView with dialog functionality and event handlers. 1: CalendarView Demo Screen 1.1

A simple calendar with events, customizable widgets and no ads.
A simple calendar with events, customizable widgets and no ads.

Simple Calendar A simple calendar with events and a customizable widget. A simple calendar with optional CalDAV synchronization. You can easily create

Owner
Nicolas Bottarini
Nicolas Bottarini
java.time Kotlin extension functions library.

Java Time Kotlin extension functions. Background Java Time became integrated to the JDK as of Java 8. It was a huge improvement over its Date predeces

Sami Eljabali 31 Mar 15, 2022
Multiplatform Date and time library for Kotlin

Klock is a Date & Time library for Multiplatform Kotlin. It is designed to be as allocation-free as possible using Kotlin inline classes, to be consis

null 681 Dec 19, 2022
A material-styled android view that provisions picking of a date, time & recurrence option, all from a single user-interface.

SublimePicker A customizable view that provisions picking of a date, time & recurrence option, all from a single user-interface. You can also view 'Su

Vikram 2.3k Jan 4, 2023
Pick a date or time on Android in style

Material DateTime Picker - Select a time/date in style Material DateTime Picker tries to offer you the date and time pickers as shown in the Material

null 4.7k Dec 29, 2022
KotlinX multiplatform date/time library

kotlinx-datetime A multiplatform Kotlin library for working with date and time. See Using in your projects for the instructions how to setup a depende

Kotlin 1.6k Jan 5, 2023
Additions for Kotlin's date & time library kotlinx-datetime

fluid-time Additions for Kotlin's date & time library kotlinx-datetime. kotlinx-datetime is very early stage and not as actively developed as other of

Marc Knaup 39 Nov 11, 2022
Android NTP time library. Get the true current time impervious to device clock time changes

TrueTime for Android Make sure to check out our counterpart too: TrueTime, an NTP library for Swift. NTP client for Android. Calculate the date and ti

Instacart 1.3k Jan 4, 2023
Compose Date Picker - Select month and year

Android DatePicker with month and year build with Compose UI

DoÄŸuÅŸ Teknoloji 47 Dec 15, 2022
A simple Cupcake Ordering App, choose flavor, pickup on a date, get order summary and send order via any other app.

Cupcake app This app contains an order flow for cupcakes with options for quantity, flavor, and pickup date. The order details get displayed on an ord

Akshat Khandelwal 0 Dec 23, 2021
MinutesAliveApp - Basic Android App that ask for your date of birth and shows your age in minutes

MinutesAliveApp Basic Android App that ask for your date of birth and shows your

JestorDev 0 Jan 30, 2022