Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: moallemi/kotlin-date-range
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.0.0
Choose a base ref
...
head repository: moallemi/kotlin-date-range
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 6 commits
  • 13 files changed
  • 2 contributors

Commits on Mar 24, 2020

  1. Update README

    moallemi committed Mar 24, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    moallemi Reza Moallemi
    Copy the full SHA
    5039011 View commit details
  2. Update badges in README

    moallemi committed Mar 24, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    moallemi Reza Moallemi
    Copy the full SHA
    8ce292f View commit details

Commits on Jul 22, 2020

  1. Add EMPTY to return an empty range

    wolflee authored and moallemi committed Jul 22, 2020
    Copy the full SHA
    8ba6aa2 View commit details

Commits on Oct 25, 2022

  1. Copy the full SHA
    fc98319 View commit details
  2. Update spotless

    moallemi committed Oct 25, 2022
    Copy the full SHA
    636d78c View commit details
  3. Remove bintray publishing

    moallemi committed Oct 25, 2022
    Copy the full SHA
    19d0b3f View commit details
11 changes: 0 additions & 11 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -45,14 +45,3 @@ jobs:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: ./gradlew publish

- name: Deploy to bintray
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
BINTRAY_USERNAME: ${{ secrets.BINTRAY_USERNAME }}
BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }}
BINTRAY_SIGNING_PASSWORD: ${{ secrets.BINTRAY_SIGNING_PASSWORD }}
run: ./gradlew bintrayUpload
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Kotlin Date Range

[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/moallemi/kotlin-date-range/CI)](https://github.com/moallemi/kotlin-date-range/actions?query=workflow%3ACI)
[![Maven Central](https://img.shields.io/maven-central/v/me.moallemi.tools/kotlin-date-range)](https://search.maven.org/artifact/me.moallemi.tools/kotlin-date-range)
[![Bintray](https://img.shields.io/bintray/v/moallemi/maven/kotlin-date-range?label=jcenter)](https://bintray.com/moallemi/maven/kotlin-date-range)
[![GitHub Workflow Status](https://github.com/moallemi/kotlin-date-range/workflows/CI/badge.svg)](https://github.com/moallemi/kotlin-date-range/actions?query=workflow%3ACI)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.moallemi.tools/kotlin-date-range/badge.svg)](https://search.maven.org/artifact/me.moallemi.tools/kotlin-date-range)


This is a tiny implementation of `rangeTo` operator for `LocalDate` that makes the syntax for loop iteration and control flow statements safe and natural to read.
This is a tiny implementation of `rangeTo` operator for `Date` and `LocalDate` that makes the syntax for loop iteration and control flow statements safe and natural to read.

## Installation

@@ -27,6 +26,8 @@ From Java SE 8 onwards, users are asked to migrate to java.time (JSR-310). For A
Using `rangeTo` operator:

```kotlin
import me.moallemi.tools.daterange.localdate.rangeTo

val startDate = LocalDate.of(2020, 3, 22)
val endDate = LocalDate.of(2020, 4, 1)
for (date in startDate..endDate) {
@@ -37,6 +38,8 @@ for (date in startDate..endDate) {
Usage with `step` function:

```kotlin
import me.moallemi.tools.daterange.localdate.rangeTo

val startDate = LocalDate.of(2020, 3, 22)
val endDate = LocalDate.of(2020, 4, 1)
for (date in startDate..endDate step 2) {
@@ -47,6 +50,8 @@ for (date in startDate..endDate step 2) {
Using with `in` operator:

```kotlin
import me.moallemi.tools.daterange.localdate.rangeTo

val startDate = LocalDate.of(2020, 1, 1)
val endDate = LocalDate.of(2020, 1, 5)

@@ -58,6 +63,8 @@ val result: Boolean = LocalDate.of(2020, 1, 2) in (startDate..endDate)
Using `rangeTo` operator:

```kotlin
import me.moallemi.tools.daterange.date.rangeTo

val calendar = Calendar.getInstance(Locale.getDefault())
calendar.set(2020, 0, 1)
val startDate = calendar.time
@@ -71,6 +78,8 @@ for (date in startDate..endDate) {
Usage with `step` function:

```kotlin
import me.moallemi.tools.daterange.date.rangeTo

for (date in startDate..endDate step 2) {
println(date)
}
11 changes: 5 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.70'
id 'org.jetbrains.kotlin.jvm' version '1.7.20'

id 'com.diffplug.gradle.spotless' version '3.27.2'
id 'com.diffplug.spotless' version '6.11.0'

id "com.jfrog.bintray" version "1.8.4"
id "maven-publish"
id "signing"
}
@@ -14,15 +13,15 @@ repositories {

spotless {
kotlin {
ktlint("0.36.0")
ktlint("0.47.1")
licenseHeaderFile project.rootProject.file('gradle/copyright.kt')
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.70"
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.7.20'

testImplementation 'junit:junit:4.13'
testImplementation 'junit:junit:4.13.2'
}

compileKotlin {
38 changes: 0 additions & 38 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
@@ -75,42 +75,4 @@ signing {
required !version.endsWith('SNAPSHOT')
useInMemoryPgpKeys(System.getenv('SIGNING_KEY'), System.getenv('SIGNING_PASSWORD'))
sign(publishing.publications["kotlinDateRange"])
}

bintray {
user = System.getenv('BINTRAY_USERNAME')
key = System.getenv('BINTRAY_API_KEY')
publications = ['kotlinDateRange']
dryRun = false
pkg {
repo = 'maven'
name = 'kotlin-date-range'
desc = project.description
websiteUrl = project.url
issueTrackerUrl = 'https://github.com/moallemi/kotlin-date-range/issues'
vcsUrl = 'https://github.com/moallemi/kotlin-date-range.git'
licenses = ['Apache-2.0']
labels = ['kotlin', 'android', 'date', 'local-date', 'date-range']
publicDownloadNumbers = false
githubRepo = 'moallemi/kotlin-date-range' //Optional Github repository
githubReleaseNotesFile = 'README.md' //Optional Github readme file
version {
name = project.version
//desc = 'optional, version-specific description'
//released = 'optional, date of the version release' //2 possible values: date in the format of 'yyyy-MM-dd'T'HH:mm:ss.SSSZZ' OR a java.util.Date instance
//vcsTag = '1.3.0'
// attributes = [] //Optional version-level attributes
gpg {
sign = true //Determines whether to GPG sign the files. The default is false
passphrase = System.getenv('BINTRAY_SIGNING_PASSWORD') //Optional. The passphrase for GPG signing'
}
mavenCentralSync {
sync = false //Optional (true by default). Determines whether to sync the version to Maven Central.
user = System.getenv('SONATYPE_USERNAME') //OSS user token
password = System.getenv('SONATYPE_PASSWORD') //OSS user password
close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
}
}
}

}
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#Sun Mar 22 12:54:09 CET 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Reza Moallemi
* Copyright 2022 Reza Moallemi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Reza Moallemi
* Copyright 2022 Reza Moallemi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Reza Moallemi
* Copyright 2022 Reza Moallemi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,4 +27,8 @@ class DateRange(
override fun iterator(): Iterator<Date> = DateIterator(start, endInclusive, stepDays)

infix fun step(days: Int) = DateRange(start, endInclusive, days)

companion object {
val EMPTY: DateRange = DateRange(Date(1), Date(0))
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Reza Moallemi
* Copyright 2022 Reza Moallemi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Reza Moallemi
* Copyright 2022 Reza Moallemi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Reza Moallemi
* Copyright 2022 Reza Moallemi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,4 +28,8 @@ class LocalDateRange(
LocalDateIterator(start, endInclusive, stepDays)

infix fun step(days: Long) = LocalDateRange(start, endInclusive, days)

companion object {
val EMPTY: LocalDateRange = LocalDateRange(LocalDate.ofEpochDay(1), LocalDate.ofEpochDay(0))
}
}
16 changes: 13 additions & 3 deletions src/test/kotlin/me/moallemi/tools/daterange/date/DateRangeTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Reza Moallemi
* Copyright 2022 Reza Moallemi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,12 @@

package me.moallemi.tools.daterange.date

import junit.framework.TestCase.assertEquals
import org.junit.Test
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date
import java.util.Locale
import junit.framework.TestCase.assertEquals
import org.junit.Test

class DateRangeTest {

@@ -66,4 +67,13 @@ class DateRangeTest {

assertEquals(expected, actual)
}

@Test
fun testEmpty() {
val expected = listOf<Date>()

val actual = DateRange.EMPTY.toList()

assertEquals(expected, actual)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Reza Moallemi
* Copyright 2022 Reza Moallemi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,9 @@

package me.moallemi.tools.daterange.localdate

import java.time.LocalDate
import junit.framework.TestCase.assertEquals
import org.junit.Test
import java.time.LocalDate

class LocalDateRangeTest {

@@ -63,4 +63,13 @@ class LocalDateRangeTest {

assertEquals(true, actual)
}

@Test
fun testEmpty() {
val expected = listOf<LocalDate>()

val actual = LocalDateRange.EMPTY.toList()

assertEquals(expected, actual)
}
}