Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r4421 - in trunk/perfsonar_base: ant src/main/java/org/perfsonar/base/util

Subject: perfsonar development work

List archive

perfsonar: r4421 - in trunk/perfsonar_base: ant src/main/java/org/perfsonar/base/util


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r4421 - in trunk/perfsonar_base: ant src/main/java/org/perfsonar/base/util
  • Date: Mon, 1 Sep 2008 06:40:03 -0400

Author: roman
Date: 2008-09-01 06:40:03 -0400 (Mon, 01 Sep 2008)
New Revision: 4421

Modified:
trunk/perfsonar_base/ant/const.properties

trunk/perfsonar_base/src/main/java/org/perfsonar/base/util/TimeDateUtil.java
Log:
new method to convert iso time format into unix time fortmat
public static long getUnixTime(String isoTimeString)




Modified: trunk/perfsonar_base/ant/const.properties
===================================================================
--- trunk/perfsonar_base/ant/const.properties 2008-09-01 10:37:28 UTC (rev
4420)
+++ trunk/perfsonar_base/ant/const.properties 2008-09-01 10:40:03 UTC (rev
4421)
@@ -13,4 +13,4 @@
# name of jar file to be created
jarfilename=perfsonar-base
# version of the product (will be included in the final name of jar file)
-version=1.0.20080725
+version=1.0.20080901

Modified:
trunk/perfsonar_base/src/main/java/org/perfsonar/base/util/TimeDateUtil.java
===================================================================
---
trunk/perfsonar_base/src/main/java/org/perfsonar/base/util/TimeDateUtil.java
2008-09-01 10:37:28 UTC (rev 4420)
+++
trunk/perfsonar_base/src/main/java/org/perfsonar/base/util/TimeDateUtil.java
2008-09-01 10:40:03 UTC (rev 4421)
@@ -28,9 +28,9 @@

/**
* Returns unix time value.
- *
+ *
* ISO format:
- *
+ *
* datetime = time | date-opt-time
* time = 'T' time-element [offset]
* date-opt-time = date-element ['T' [time-element] [offset]]
@@ -50,71 +50,91 @@
public static String getUnixTime(Parameter timeParemeter)
throws PerfSONARException {

- if (timeParemeter == null)
+ if (timeParemeter == null)
return null;

- String unixTime = _getUnixTime(timeParemeter);
- if (unixTime == null)
- unixTime = timeParemeter.getParameterValue();
+ String unixTime = _getUnixTime(timeParemeter);
+ if (unixTime == null)
+ unixTime = timeParemeter.getParameterValue();

- return unixTime;
+ return unixTime;

}

protected static String _getUnixTime(Parameter timeParemeter)
throws PerfSONARException {

- Vector pchildren = timeParemeter.getChildrenByType("time");
- Element subelement = null;
- try {
- subelement = (Element) pchildren.firstElement();
- } catch (NoSuchElementException nseex) {
- // TODO handle.
- }
+ Vector pchildren = timeParemeter.getChildrenByType("time");
+ Element subelement = null;
+ try {
+ subelement = (Element) pchildren.firstElement();
+ } catch (NoSuchElementException nseex) {
+ // TODO handle.
+ }

- if (subelement == null)
- return null;
+ if (subelement == null)
+ return null;

- if (!subelement.getLocalName().equals("time"))
- throw new PerfSONARException(
+ if (!subelement.getLocalName().equals("time"))
+ throw new PerfSONARException(
"error.parameter",
"TimeDateUtil._getUnixTime: wrong type of parameter; "
+ "it should be time type");

- Time time = (Time) subelement;
- String unixTimeString = "";
+ Time time = (Time) subelement;
+ String unixTimeString = "";

- if (time.getType().trim().equalsIgnoreCase("unix")) {
+ if (time.getType().trim().equalsIgnoreCase("unix")) {

- unixTimeString = time.getValue();
+ unixTimeString = time.getValue();

- } else if (time.getType().trim().equalsIgnoreCase("iso")) {
+ } else if (time.getType().trim().equalsIgnoreCase("iso")) {

- String isoTimeString = time.getValue();
- try {
+ String isoTimeString = time.getValue();
+ try {

- DateTimeFormatter dtf =
ISODateTimeFormat.dateTimeParser();
- DateTime dt = dtf.parseDateTime(isoTimeString);
- unixTimeString = Long.toString(dt.getMillis()/1000);
+ DateTimeFormatter dtf = ISODateTimeFormat.dateTimeParser();
+ DateTime dt = dtf.parseDateTime(isoTimeString);
+ unixTimeString = Long.toString(dt.getMillis()/1000);

- } catch (Exception ex) {
- throw new PerfSONARException(
- "error.parameter",
- "TimeDateUtil._getUnixTime: ISO time coversion is
wrong; "
- + ex.toString());
- }
+ } catch (Exception ex) {
+ throw new PerfSONARException(
+ "error.parameter",
+ "TimeDateUtil._getUnixTime: ISO time coversion is
wrong; "
+ + ex.toString());
+ }

- } else {
+ } else {

- throw new PerfSONARException(
+ throw new PerfSONARException(
"error.parameter",
"TimeDateUtil._getUnixTime: "
+ "Time type " + time.getType() + "is not supported");

- }
+ }

- return unixTimeString;
+ return unixTimeString;

}

+
+ public static long getUnixTime(String isoTimeString)
+ throws PerfSONARException {
+
+ try {
+
+ DateTimeFormatter dtf = ISODateTimeFormat.dateTimeParser();
+ DateTime dt = dtf.parseDateTime(isoTimeString);
+ return dt.getMillis()/1000;
+
+ } catch (Exception ex) {
+ throw new PerfSONARException(
+ "error.parameter",
+ "TimeDateUtil.getUnixTime: ISO time coversion is
wrong; "
+ + ex.toString());
+ }
+
+ }
+
+
} //TimeDateUtil



  • perfsonar: r4421 - in trunk/perfsonar_base: ant src/main/java/org/perfsonar/base/util, svnlog, 09/01/2008

Archive powered by MHonArc 2.6.16.

Top of Page