Skip to content

Commit

Permalink
Adding date utility class
Browse files Browse the repository at this point in the history
  • Loading branch information
hpedrorodrigues committed May 31, 2017
1 parent 0fc5005 commit 5d33cd3
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.OkraScheduler</groupId>
<artifactId>OkraApi</artifactId>
<version>1.4.4</version>
<version>1.4.5</version>

<properties>
<source.enconding>UTF-8</source.enconding>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/okra/base/AbstractOkra.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

import lombok.Data;
import okra.base.model.OkraItem;
import okra.index.IndexDef;
import okra.index.Ordering;
import okra.base.model.index.IndexDef;
import okra.base.model.index.Ordering;

import java.util.Arrays;
import java.util.List;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/okra/base/Okra.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
package okra.base;

import okra.base.model.OkraItem;
import okra.index.IndexDef;
import okra.base.model.index.IndexDef;

import java.util.List;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/okra/base/async/AbstractOkraAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import lombok.Setter;
import okra.base.AbstractOkra;
import okra.base.model.OkraItem;
import okra.index.IndexDef;
import okra.base.model.index.IndexDef;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* SOFTWARE.
*
*/
package okra.index;
package okra.base.model.index;

import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* SOFTWARE.
*
*/
package okra.index;
package okra.base.model.index;

public enum Ordering {

Expand Down
49 changes: 49 additions & 0 deletions src/main/java/okra/util/DateUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2017 Okra Scheduler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package okra.util;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

public final class DateUtil {

public static Date toDate(final LocalDateTime dateTime) {
if (dateTime == null) {
return null;
}

return Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
}

public static LocalDateTime toLocalDateTime(final Date date) {
if (date == null) {
return null;
}

return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
}

public static Date nowMinusSeconds(final long seconds) {
return DateUtil.toDate(LocalDateTime.now().minusSeconds(seconds));
}
}

0 comments on commit 5d33cd3

Please sign in to comment.