You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2014/12/02 12:29:37 UTC
[4/8] jena git commit: Date and dateTime formatting.
Date and dateTime formatting.
This closes #12
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/05fae18a
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/05fae18a
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/05fae18a
Branch: refs/heads/master
Commit: 05fae18a1d57e71f1eb6d59c15ad88617be746cb
Parents: 16ebf70 114966b
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Dec 2 10:36:46 2014 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Dec 2 10:36:46 2014 +0000
----------------------------------------------------------------------
jena-arq/pom.xml | 5 ++
.../hp/hpl/jena/sparql/util/StringUtils.java | 5 +-
.../java/com/hp/hpl/jena/sparql/util/Utils.java | 56 ++++++++--------
.../com/hp/hpl/jena/sparql/util/TS_Util.java | 4 +-
.../com/hp/hpl/jena/sparql/util/TestUtils.java | 68 ++++++++++++++++++++
jena-parent/pom.xml | 13 +++-
6 files changed, 115 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/05fae18a/jena-arq/pom.xml
----------------------------------------------------------------------
diff --cc jena-arq/pom.xml
index 4697ee5,fdaca07..6f03367
--- a/jena-arq/pom.xml
+++ b/jena-arq/pom.xml
@@@ -98,8 -110,14 +98,13 @@@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
- <version>1.0</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
- <version>3.3.2</version>
+ </dependency>
++
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/jena/blob/05fae18a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/Utils.java
----------------------------------------------------------------------
diff --cc jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/Utils.java
index 529fa1d,4f52421..e1ce615
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/Utils.java
+++ b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/Utils.java
@@@ -32,7 -32,13 +32,12 @@@ import com.hp.hpl.jena.datatypes.xsd.XS
public class Utils
{
- static public String className(Object obj) {
-
- private static final FastDateFormat fullFmtZ = FastDateFormat.getInstance("yyyy/MM/dd HH:mm:ss z");
- private static final FastDateFormat yyyymmddFmt = FastDateFormat.getInstance("yyyy-MM-dd");
- private static final FastDateFormat fullFmt = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS");
- private static final FastDateFormat hhmmssSS = FastDateFormat.getInstance("HH:mm:ss.SSS");
++ 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-dd") ;
++ private static final FastDateFormat dateTimeFmt_XSD = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS") ;
++ private static final FastDateFormat timeFmt_hhmmssSS = FastDateFormat.getInstance("HH:mm:ss.SSS");
+
+ static public String className(Object obj) {
if ( obj == null )
return "null" ;
return classShortName(obj.getClass()) ;
@@@ -63,42 -69,35 +68,35 @@@
/** Return "now" as readable string (date in yyyy/MM/dd format) */
public static String nowAsString()
- { return nowAsString("yyyy/MM/dd HH:mm:ss z") ; }
- { return nowAsString(fullFmtZ) ; }
++ { return nowAsString(dateTimeFmt_display) ; }
public static String nowAsString(String formatString)
{
- DateFormat df = new SimpleDateFormat(formatString) ;
+ FastDateFormat df = FastDateFormat.getInstance(formatString) ;
return df.format(new Date()) ;
}
-
- // public static XSDDateTime calendarToXSDDateTime(Calendar cal)
- // {
- // return new XSDDateTime(cal) ;
- // }
- //
- // public static XSDDateTime calendarToXSDDate(Calendar cal)
- // {
- // // Ensure it is an XSDDate, not a dateTime.
- // return (XSDDateTime)XSDDatatype.XSDdate.parse(calendarToXSDDateString(cal)) ;
- // }
-
+ public static String nowAsString(FastDateFormat dateFormat)
+ {
+ return dateFormat.format(new Date()) ;
+ }
+
public static String calendarToXSDDateTimeString(Calendar cal)
{
- return calendarToXSDString(cal, "yyyy-MM-dd'T'HH:mm:ss.SSS") ;
- return calendarToXSDString(cal, fullFmt) ;
++ return calendarToXSDString(cal, dateTimeFmt_XSD) ;
}
public static String calendarToXSDDateString(Calendar cal)
{
- return calendarToXSDString(cal, "yyyy-MM-dd") ;
- return calendarToXSDString(cal, yyyymmddFmt) ;
++ return calendarToXSDString(cal, dateFmt_yyyymmdd) ;
}
public static String calendarToXSDTimeString(Calendar cal)
{
- return calendarToXSDString(cal, "HH:mm:ss.SSS");
- return calendarToXSDString(cal, hhmmssSS);
++ return calendarToXSDString(cal, timeFmt_hhmmssSS);
}
-
- private static String calendarToXSDString(Calendar cal, String fmt)
+
+ private static String calendarToXSDString(Calendar cal, FastDateFormat fmt )
{
// c.f. Constructor on Jena's XSDDateTime
// Only issue is that it looses the timezone through (Xerces)
http://git-wip-us.apache.org/repos/asf/jena/blob/05fae18a/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TS_Util.java
----------------------------------------------------------------------
diff --cc jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TS_Util.java
index db177af,db177af..ea4f6e9
--- a/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TS_Util.java
+++ b/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TS_Util.java
@@@ -26,7 -26,7 +26,9 @@@ import org.junit.runners.Suite.SuiteCla
@SuiteClasses( {
TestDateTimeParsing.class ,
TestList.class ,
-- TestVersion.class
++ TestVersion.class ,
++ TestUtils.class ,
++ TestFmtUtils.class
})
public class TS_Util
http://git-wip-us.apache.org/repos/asf/jena/blob/05fae18a/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TestUtils.java
----------------------------------------------------------------------
diff --cc jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TestUtils.java
index 0000000,0000000..e2d59b7
new file mode 100644
--- /dev/null
+++ b/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TestUtils.java
@@@ -1,0 -1,0 +1,68 @@@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements. See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership. The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing, software
++ * distributed under the License is distributed on an "AS IS" BASIS,
++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
++ * See the License for the specific language governing permissions and
++ * limitations under the License.
++ */
++package com.hp.hpl.jena.sparql.util;
++
++import static com.hp.hpl.jena.sparql.util.Utils.calendarToXSDDateString;
++import static com.hp.hpl.jena.sparql.util.Utils.calendarToXSDDateTimeString;
++import static com.hp.hpl.jena.sparql.util.Utils.calendarToXSDTimeString;
++import static org.junit.Assert.*;
++
++import java.util.Calendar;
++import java.util.GregorianCalendar;
++import java.util.TimeZone;
++
++import org.junit.Test;
++
++public class TestUtils {
++
++ @Test
++ public void testCalendarToXSDDateTimeString() throws Exception {
++ Calendar cal = createCalendar(1984, Calendar.MARCH, 22, 14, 32, 1,"Z") ;
++ assertEquals("1984-03-22T14:32:01.000+00:00", calendarToXSDDateTimeString(cal));
++ cal.setTimeZone(TimeZone.getTimeZone("MST"));
++ assertEquals("1984-03-22T14:32:01.000-07:00", calendarToXSDDateTimeString(cal));
++ }
++
++ @Test
++ public void testCalendarToXSDDateString() throws Exception {
++ Calendar cal = createCalendar(1984, Calendar.MARCH, 22, 23, 59, 1, "Z");
++ cal.setTimeZone(TimeZone.getTimeZone("Z")) ;
++ assertEquals("1984-03-22+00:00", calendarToXSDDateString(cal));
++ cal.setTimeZone(TimeZone.getTimeZone("MST"));
++ assertEquals("1984-03-22-07:00", calendarToXSDDateString(cal));
++
++ }
++
++ @Test
++ public void testCalendarToXSDTimeString() throws Exception {
++ Calendar cal = createCalendar(1984, Calendar.MARCH, 22, 14, 32, 1, "GMT+01:00");
++ cal.setTimeZone(TimeZone.getTimeZone("GMT+01:00")) ;
++ // Moves the cal
++ assertEquals("13:32:01.000+01:00", calendarToXSDTimeString(cal));
++ cal.setTimeZone(TimeZone.getTimeZone("MST"));
++ assertEquals("13:32:01.000-07:00", calendarToXSDTimeString(cal));
++ }
++
++ private static Calendar createCalendar(int year, int month, int dayOfMonth, int hourOfDay,
++ int minute, int second, String tz) {
++ GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone(tz)) ;
++ cal.set(year, month, dayOfMonth, hourOfDay, minute, second) ;
++ cal.set(Calendar.MILLISECOND, 0) ;
++ return cal ;
++ }
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/05fae18a/jena-parent/pom.xml
----------------------------------------------------------------------
diff --cc jena-parent/pom.xml
index ce851e4,81ccd61..e3bd691
--- a/jena-parent/pom.xml
+++ b/jena-parent/pom.xml
@@@ -51,7 -51,7 +51,6 @@@
<ver.junit>4.11</ver.junit>
<ver.xerces>2.11.0</ver.xerces>
<ver.jsonldjava>0.5.1</ver.jsonldjava>
-- <ver.commons-fileupload>1.3.1</ver.commons-fileupload>
<!-- These are connected because solr4j depends on httpclient as well -->
<ver.httpclient>4.2.6</ver.httpclient>
@@@ -131,28 -131,9 +130,38 @@@
</dependency>
<dependency>
+ <groupId>org.apache.thrift</groupId>
+ <artifactId>libthrift</artifactId>
+ <version>0.9.2</version>
+ <exclusions>
+ <!-- Use whatever version Jena is using -->
+ <exclusion>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpcore</artifactId>
+ </exclusion>
++ <exclusion>
++ <groupId>org.apache.commons</groupId>
++ <artifactId>commons-lang3</artifactId>
++ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-csv</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
++ <groupId>org.apache.commons</groupId>
++ <artifactId>commons-lang3</artifactId>
++ <version>3.3.2</version>
++ </dependency>
++
++ <dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
-- <version>${ver.commons-fileupload}</version>
++ <version>1.3.1</version>
</dependency>
<dependency>