Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

joda time to java 8 api #80

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions rulette-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
<description>Core classes for Rulette Framework</description>

<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
import java.time.ZoneId;

class InputDateValue implements IInputValue<Date>, Serializable {
private static final long serialVersionUID = 5666450390675442878L;
private static final String DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
private static final DateTimeFormatter formatter = DateTimeFormat.forPattern(DATE_PATTERN);
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_PATTERN);
private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat(DATE_PATTERN);

private final Date value;

public InputDateValue (String value) {
this.value = value == null || value.isEmpty() ? null : formatter.parseDateTime(value).toDate();
this.value = value == null || value.isEmpty() ? null : this.DatefromLocalDateTime(LocalDateTime.parse((CharSequence)value, formatter));
}

@Override
public boolean isEmpty() {
return value == null;
Expand All @@ -31,7 +33,7 @@ public Date getValue() {

@Override
public int compareTo(String obj) {
return this.value.compareTo(formatter.parseDateTime(obj).toDate());
return this.value.compareTo(DatefromLocalDateTime(LocalDateTime.parse(obj, formatter)));
}

@Override
Expand Down Expand Up @@ -59,9 +61,14 @@ public boolean equals(Object obj) {
return that.getValue().equals(this.value);
}
}

@Override
public String toString() {
return this.value == null ? "" : SIMPLE_DATE_FORMAT.format(this.value);
}

private Date DatefromLocalDateTime(LocalDateTime ldt){
return Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.github.kislayverma.rulette.core.util;

import com.github.kislayverma.rulette.core.annotations.RuletteInput;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import java.lang.reflect.Field;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -16,9 +14,10 @@
*/
public class RuletteInputProcessor {

private static final DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

public static Map<String, String> generateInputMap(Object request) throws IllegalAccessException {

Map<String, String> inputMap = new HashMap<>();
Field[] fieldsInObject = request.getClass().getDeclaredFields();
for(Field field : fieldsInObject){
Expand All @@ -34,7 +33,7 @@ public static Map<String, String> generateInputMap(Object request) throws Illega
fieldValueString = "";
}else {
if(fieldValue instanceof Date){
fieldValueString = new DateTime(fieldValue).toString(formatter);
fieldValueString = LocalDateTime.parse((CharSequence)fieldValue, formatter).format(formatter);
}else {
fieldValueString = fieldValue.toString();
}
Expand Down