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

Remove joda-time and use Java 8 time instead #67

Open
wants to merge 3 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
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
dist: trusty
language: java
jdk:
# - openjdk7
# - oraclejdk7 disabling due to the container not being able to set JAVA_HOME correctly
- oraclejdk8
- openjdk8
- oraclejdk11
Expand Down
24 changes: 8 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<spotbugs.plugin>4.0.0</spotbugs.plugin>
<jacoco.version>0.8.5</jacoco.version>
<javadoc.plugin>3.2.0</javadoc.plugin>
<joda.version>2.10.6</joda.version>
</properties>

<url>https://github.com/damnhandy/Handy-URI-Templates</url>
Expand Down Expand Up @@ -277,8 +276,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

Expand Down Expand Up @@ -328,11 +327,11 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>${javadoc.plugin}</version>
<configuration>
<source>1.7</source>
<source>1.8</source>
<encoding>UTF-8</encoding>
<maxmemory>1g</maxmemory>
<links>
<link>http://docs.oracle.com/javase/7/docs/api/</link>
<link>http://docs.oracle.com/javase/8/docs/api/</link>
</links>
</configuration>
</plugin>
Expand Down Expand Up @@ -522,11 +521,11 @@
<version>${javadoc.plugin}</version>
<configuration>
<additionalJOption>-Xdoclint:none</additionalJOption>
<source>1.7</source>
<source>1.8</source>
<encoding>UTF-8</encoding>
<maxmemory>1g</maxmemory>
<links>
<link>http://docs.oracle.com/javase/7/docs/api/</link>
<link>http://docs.oracle.com/javase/8/docs/api/</link>
</links>
</configuration>
<executions>
Expand All @@ -552,11 +551,11 @@
<version>${javadoc.plugin}</version>
<configuration>
<additionalJOption>-Xdoclint:none</additionalJOption>
<source>1.7</source>
<source>1.8</source>
<encoding>UTF-8</encoding>
<maxmemory>1g</maxmemory>
<links>
<link>http://docs.oracle.com/javase/7/docs/api/</link>
<link>http://docs.oracle.com/javase/8/docs/api/</link>
</links>
</configuration>
</plugin>
Expand Down Expand Up @@ -647,12 +646,5 @@
<version>${http.client}</version>
<scope>test</scope>
</dependency>

<!-- Date/Time Utilities -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda.version}</version>
</dependency>
</dependencies>
</project>
18 changes: 11 additions & 7 deletions src/main/java/com/damnhandy/uri/template/UriTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
package com.damnhandy.uri.template;

import com.damnhandy.uri.template.impl.*;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -84,7 +85,7 @@ public enum Encoding
/**
*
*/
transient DateTimeFormatter defaultDateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
transient DateTimeFormatter defaultDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

/**
* @deprecated Replaced by {@link #defaultDateTimeFormatter defaultDateTimeFormatter}
Expand Down Expand Up @@ -469,7 +470,7 @@ public Map<String, Object> getValues()
*/
public UriTemplate withDefaultDateFormat(String dateFormatString)
{
return this.withDefaultDateFormat(DateTimeFormat.forPattern(dateFormatString));
return this.withDefaultDateFormat(DateTimeFormatter.ofPattern(dateFormatString));
}

private UriTemplate withDefaultDateFormat(DateTimeFormatter dateTimeFormatter)
Expand All @@ -492,7 +493,7 @@ public UriTemplate withDefaultDateFormat(DateFormat dateFormat)
throw new IllegalArgumentException(
"The only supported subclass of java.text.DateFormat is java.text.SimpleDateFormat");
}
defaultDateTimeFormatter = DateTimeFormat.forPattern(((SimpleDateFormat) dateFormat).toPattern());
defaultDateTimeFormatter = DateTimeFormatter.ofPattern(((SimpleDateFormat) dateFormat).toPattern());
return this;
}

Expand Down Expand Up @@ -678,7 +679,10 @@ else if (varSpec.getModifier() != Modifier.EXPLODE)
*/
if (value instanceof Date)
{
value = defaultDateTimeFormatter.print(new DateTime((Date) value));
final Instant instant = ((Date) value).toInstant();
// TODO should we rely on system default zone ID?
final LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
value = defaultDateTimeFormatter.format(localDateTime);
}
/*
* The variable value contains a list of values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import com.damnhandy.uri.template.impl.Operator;
import com.damnhandy.uri.template.impl.UriTemplateParser;
import com.damnhandy.uri.template.impl.VarSpec;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Map;
Expand Down Expand Up @@ -92,7 +91,7 @@ public final class UriTemplateBuilder
*/
public UriTemplateBuilder withDefaultDateFormat(String dateFormatString)
{
return this.withDefaultDateFormat(DateTimeFormat.forPattern(dateFormatString));
return this.withDefaultDateFormat(DateTimeFormatter.ofPattern(dateFormatString));
}

private UriTemplateBuilder withDefaultDateFormat(DateTimeFormatter dateTimeFormatter)
Expand All @@ -115,7 +114,7 @@ public UriTemplateBuilder withDefaultDateFormat(DateFormat dateFormat)
throw new IllegalArgumentException(
"The only supported subclass of java.text.DateFormat is java.text.SimpleDateFormat");
}
defaultDateTimeFormatter = DateTimeFormat.forPattern(((SimpleDateFormat) dateFormat).toPattern());
defaultDateTimeFormatter = DateTimeFormatter.ofPattern(((SimpleDateFormat) dateFormat).toPattern());
return this;
}

Expand Down