Giter VIP home page Giter VIP logo

datesbetween's Introduction

GitHub

datesbetween

A Scala library for calculating all dates between two given dates.

Examples

To use the library, import the following:

import zycrophat.datesbetween.DatesBetween._

A Seq of dates can be calculated as followed:

val start = LocalDate.of(2020, 3, 1)
val end = LocalDate.of(2020, 3, 6)

val theDatesBetween = datesBetween(start, end) // will include 2020-03-01, ... , 2020-03-06

Using inclusive (wihch is the default) and exclusive the upper and lower bounds can be adjusted:

val start = LocalDate.of(2020, 3, 1)
val end = LocalDate.of(2020, 3, 6)

val theDatesBetween = datesBetween(start, end.exclusive) // will include 2020-03-01, ... , 2020-03-05

You can also use LocalDateTime instead of LocalDate:

val start = LocalDate.of(2020, 3, 1).atStartOfDay()
val end = LocalDate.of(2020, 3, 6).atTime(13, 37)

val theDatesBetween = datesBetween(start.exclusive, end.exclusive) // will include 2020-03-02, ... , 2020-03-05

Or your can use a mixture of different types:

val start = LocalDate.of(2020, 3, 1)
val end = LocalDate.of(2020, 3, 6).atTime(13, 37)

val theDatesBetween = datesBetween(start.exclusive, end.exclusive) // will include 2020-03-02, ... , 2020-03-05

For other types you must provide an implicit conversion function, e.g.:

val start = ZonedDateTime.parse("2020-03-01T10:15:30+01:00")
val end = ZonedDateTime.parse("2020-03-06T13:37:42+02:00")

implicit val zonedDateTimeToLocalDate: ZonedDateTime => LocalDate = (zdt: ZonedDateTime) => zdt.toLocalDate

val theDatesBetween = datesBetween(start.exclusive, end) // will include 2020-03-02, ... , 2020-03-06

You can also the and method for an even more fluent experience:

val start = LocalDate.of(2020, 3, 1)
val end = LocalDate.of(2020, 3, 6).atTime(13, 37)

val theDatesBetween = datesBetween(start.exclusive and end.exclusive, Period.ofDays(2))

Prerequisites

  • Tested on JDK 11 (but should work on JDK 8)

How to run tests

$ sbt test

To run with coverage report:

$ sbt test coverageReport

A scoverage report will be created in the directory target/scala-2.11/scoverage-report.

How to build

$ sbt package

License

MIT License

datesbetween's People

Watchers

Andreas Steffan 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.