Skip to content

Commit

Permalink
Merge pull request #603 from afs/dependency-updates
Browse files Browse the repository at this point in the history
JENA-1756: Dependency updates
  • Loading branch information
afs committed Sep 12, 2019
2 parents c1a8403 + fa57c60 commit 110309f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 66 deletions.
Expand Up @@ -18,29 +18,22 @@

package org.apache.jena.atlas.lib;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar ;
import java.util.Date ;
import java.util.GregorianCalendar ;

import org.apache.commons.lang3.time.FastDateFormat ;

public class DateTimeUtils {

// Include timezone (even xsd:dates have timezones; Calendars have timezones)
// NB in SimpleDateFormat != FastDateFormat
// SimpleDateFormat does not format Calendars.
// SimpleDateFormat has "X" for ISO format tmezones (+00:00)
// FastDateFormat uses "ZZ" for this.
private static final FastDateFormat dateTimeFmt_display = FastDateFormat.getInstance("yyyy/MM/dd HH:mm:ss z") ;
private static final FastDateFormat dateFmt_yyyymmdd = FastDateFormat.getInstance("yyyy-MM-ddZZ") ;
// For milliseconds == 0
private static final FastDateFormat dateTimeFmt_XSD_ms0 = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ssZZ") ;
// For milliseconds != 0
private static final FastDateFormat dateTimeFmt_XSD_ms = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSSZZ") ;
// For milliseconds == 0
private static final FastDateFormat timeFmt_XSD_ms0 = FastDateFormat.getInstance("HH:mm:ssZZ") ;
// For milliseconds != 0
private static final FastDateFormat timeFmt_XSD_ms = FastDateFormat.getInstance("HH:mm:ss.SSSZZ") ;
// Use xxx to get +00:00 format with DateTimeFormatter
private static final DateTimeFormatter dateTimeFmt_display = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss zz");
private static final DateTimeFormatter dateFmt_yyyymmdd = DateTimeFormatter.ofPattern("yyyy-MM-ddxxx");
private static final DateTimeFormatter dateTimeFmt_XSD_ms0 = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
private static final DateTimeFormatter dateTimeFmt_XSD_ms = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSxxx");
private static final DateTimeFormatter timeFmt_XSD_ms0 = DateTimeFormatter.ofPattern("HH:mm:ssxxx");
private static final DateTimeFormatter timeFmt_XSD_ms = DateTimeFormatter.ofPattern("HH:mm:ss.SSSxxx");

public static String nowAsXSDDateTimeString() {
return calendarToXSDDateTimeString(new GregorianCalendar()) ;
Expand All @@ -60,68 +53,42 @@ public static String nowAsString(String formatString) {
return df.format(new Date()) ;
}

public static String nowAsString(FastDateFormat dateFormat) {
return dateFormat.format(new Date()) ;
public static String nowAsString(DateTimeFormatter dateFormat) {
ZonedDateTime now = ZonedDateTime.now();
return dateFormat.format(now);
}

private static boolean hasZeroMilliSeconds(Calendar cal) {
return ! cal.isSet(Calendar.MILLISECOND) || cal.get(Calendar.MILLISECOND) == 0 ;
}

// Canonical fom : if ms == 0, don't include in the string.
// Canonical form : if ms == 0, don't include in the string.
public static String calendarToXSDDateTimeString(Calendar cal) {
FastDateFormat fmt = hasZeroMilliSeconds(cal)
? dateTimeFmt_XSD_ms0
: dateTimeFmt_XSD_ms ;
DateTimeFormatter fmt = hasZeroMilliSeconds(cal)
? dateTimeFmt_XSD_ms0
: dateTimeFmt_XSD_ms ;
return calendarToXSDString(cal, fmt) ;
}

public static String calendarToXSDDateString(Calendar cal) {
return calendarToXSDString(cal, dateFmt_yyyymmdd) ;
String x = calendarToXSDString(cal, dateFmt_yyyymmdd) ;
if ( x.endsWith("Z") )
x = x.substring(0, x.length()-1)+"+00:00";
return x;
}

// Canonical fom : if ms == 0, don't include in the string.
public static String calendarToXSDTimeString(Calendar cal) {
FastDateFormat fmt = hasZeroMilliSeconds(cal)
? timeFmt_XSD_ms0
: timeFmt_XSD_ms ;
DateTimeFormatter fmt = hasZeroMilliSeconds(cal)
? timeFmt_XSD_ms0
: timeFmt_XSD_ms ;
return calendarToXSDString(cal, fmt) ;
}

private static String calendarToXSDString(Calendar cal, FastDateFormat fmt) {
String lex = fmt.format(cal) ;
private static String calendarToXSDString(Calendar cal, DateTimeFormatter fmt) {
ZonedDateTime zdt = ((GregorianCalendar)cal).toZonedDateTime();
String lex = fmt.format(zdt) ;
// lex = lex + calcTimezone(cal) ;
return lex ;
}

// Not needed because of FastDateFormat
// private static String calcTimezone(Calendar cal) {
// Date date = cal.getTime() ;
// TimeZone z = cal.getTimeZone() ;
// int tz = z.getRawOffset() ;
//
// if ( z.inDaylightTime(date) ) {
// int tzDst = z.getDSTSavings() ;
// tz = tz + tzDst ;
// }
//
// String sign = "+" ;
// if ( tz < 0 ) {
// sign = "-" ;
// tz = -tz ;
// }
//
// int tzH = tz / (60 * 60 * 1000) ; // Integer divide towards zero.
// int tzM = (tz - tzH * 60 * 60 * 1000) / (60 * 1000) ;
//
// String tzH_str = Integer.toString(tzH) ;
// String tzM_str = Integer.toString(tzM) ;
//
// if ( tzH < 10 )
// tzH_str = "0" + tzH_str ;
// if ( tzM < 10 )
// tzM_str = "0" + tzM_str ;
// return sign + tzH_str + ":" + tzM_str ;
// }
}

14 changes: 7 additions & 7 deletions pom.xml
Expand Up @@ -66,20 +66,20 @@
POM for the correct dependency versions
and use that or later.
-->
<ver.jsonldjava>0.12.3</ver.jsonldjava>
<ver.jsonldjava>0.12.5</ver.jsonldjava>
<ver.jackson>2.9.9</ver.jackson>
<ver.jackson-databind>2.9.9.3</ver.jackson-databind>

<ver.commonsio>2.6</ver.commonsio>
<ver.commonscli>1.4</ver.commonscli>
<ver.commonslang3>3.4</ver.commonslang3>
<ver.commonscsv>1.5</ver.commonscsv>
<ver.commonslang3>3.9</ver.commonslang3>
<ver.commonscsv>1.7</ver.commonscsv>
<ver.commons-codec>1.13</ver.commons-codec>
<ver.commons-compress>1.19</ver.commons-compress>

<ver.dexxcollection>0.7</ver.dexxcollection>

<ver.httpclient>4.5.5</ver.httpclient>
<ver.httpclient>4.5.10</ver.httpclient>
<ver.httpcore>4.4.9</ver.httpcore>
<!-- Normally, these are the same as the above
In the case of 4.2.6, there isn't a httpcore-osgi.
Expand All @@ -99,7 +99,7 @@

<ver.mockito>1.9.5</ver.mockito>
<ver.awaitility>3.1.0</ver.awaitility>
<ver.micrometer>1.1.3</ver.micrometer>
<ver.micrometer>1.2.1</ver.micrometer>

<jdk.version>1.8</jdk.version>
<targetJdk>${jdk.version}</targetJdk>
Expand Down Expand Up @@ -378,7 +378,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
<version>4.4</version>
</dependency>

<!-- supports persistent data structures -->
Expand Down Expand Up @@ -933,7 +933,7 @@
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>1.2</version>
<version>3.1.1</version>
</dependency>
</dependencies>
</plugin>
Expand Down

0 comments on commit 110309f

Please sign in to comment.