Skip to content

Commit

Permalink
Add support of LocalDate into DateTimeUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed Jun 5, 2019
1 parent a93ddf4 commit 032016d
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/org/camunda/latera/bss/utils/DateTimeUtil.groovy
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package org.camunda.latera.bss.utils

import java.util.Locale
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit

class DateTimeUtil {
static final DateTimeFormatter ISO_FORMAT = DateTimeFormatter.ISO_OFFSET_DATE_TIME
static final DateTimeFormatter ISO_FORMAT = DateTimeFormatter.ISO_OFFSET_DATE_TIME
static final DateTimeFormatter ISO_FORMAT_NO_TZ = DateTimeFormatter.ISO_LOCAL_DATE_TIME
static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern('yyyy-MM-dd')
static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern('yyyy-MM-dd')
static final DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern('yyyy-MM-dd HH:mm:ss')
static final DateTimeFormatter FULL_DATE_FORMAT = DateTimeFormatter.ofPattern('dd MMMM yyyy')
static final DateTimeFormatter SIMPLE_DATE_FORMAT = DateTimeFormatter.ofPattern('dd.MM.yyyy')
static final DateTimeFormatter SIMPLE_DATE_FORMAT = DateTimeFormatter.ofPattern('dd.MM.yyyy')
static final DateTimeFormatter SIMPLE_DATE_TIME_FORMAT = DateTimeFormatter.ofPattern('dd.MM.yyyy HH:mm:ss')
static final String DATE_TIME_FORMAT_ORACLE = 'DD.MM.YYYY HH24:MI:SS'

Expand Down Expand Up @@ -77,6 +78,10 @@ class DateTimeUtil {
}

static String iso(Date input) {
return local(input).format(this.ISO_FORMAT_NO_TZ)
}

static String iso(LocalDate input) {
return input.format(this.ISO_FORMAT_NO_TZ)
}

Expand All @@ -92,6 +97,10 @@ class DateTimeUtil {
return input.toInstant().atZone(zone)
}

static ZonedDateTime atZone(LocalDate input , ZoneId zone) {
return input.atStartOfDay().atZone(zone)
}

static ZonedDateTime atZone(LocalDateTime input = now(), ZoneId zone) {
return input.atZone(zone)
}
Expand All @@ -100,12 +109,16 @@ class DateTimeUtil {
return atZone(input, ZoneId.systemDefault())
}

static ZonedDateTime local(LocalDate input) {
return atZone(input, ZoneId.systemDefault())
}

static ZonedDateTime local(LocalDateTime input = now()) {
return atZone(input, ZoneId.systemDefault())
}

static ZonedDateTime local(ZonedDateTime input) {
return input
return input.withZoneSameInstant(ZoneId.systemDefault())
}

static LocalDateTime nextSecond(LocalDateTime input = now()) {
Expand All @@ -124,6 +137,14 @@ class DateTimeUtil {
return input.minusSeconds(1)
}

static LocalDateTime dayBegin(Date input) {
return local(input).toLocalDateTime()
}

static LocalDateTime dayBegin(LocalDate input) {
return local(input).toLocalDateTime()
}

static LocalDateTime dayBegin(LocalDateTime input = now()) {
return input.truncatedTo(ChronoUnit.DAYS)
}
Expand Down Expand Up @@ -157,6 +178,10 @@ class DateTimeUtil {
}

static Boolean isDate(input) {
return (input instanceof Date) || (input instanceof LocalDateTime) || (input instanceof ZonedDateTime)
return (input instanceof Date) || (input instanceof LocalDate) || (input instanceof LocalDateTime) || (input instanceof ZonedDateTime)
}

static Boolean isDateTime(input) {
return (input instanceof LocalDateTime) || (input instanceof ZonedDateTime)
}
}

0 comments on commit 032016d

Please sign in to comment.