Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 177433

Summary: [XML Data Source Improvements] Addition of XML Duration Data Type
Product: z_Archived Reporter: malcolm davis <malcolmdavis>
Component: BIRTAssignee: Mingxia Wu <mwu>
Status: VERIFIED FIXED QA Contact: Tianli Zhang <tzhang>
Severity: enhancement    
Priority: P3 CC: bluesoldier, lchan, lzhu, malcolmdavis, xxue
Version: 2.1.0Keywords: plan
Target Milestone: 2.5.0 M6   
Hardware: All   
OS: All   
Whiteboard: Autoed

Description malcolm davis CLA 2007-03-14 17:15:33 EDT
The duration data type is used to specify a time interval.  Many XML data sources use the duration data type.  [Duration Data Type seems like a major oversight, and one that should be easy to remedy]

The time interval is specified in the following form "PnYnMnDTnHnMnS" where:

* P indicates the period (required)
* nY indicates the number of years
* nM indicates the number of months
* nD indicates the number of days
* T indicates the start of a time section (required if you are going to specify hours, minutes, or seconds)
* nH indicates the number of hours
* nM indicates the number of minutes
* nS indicates the number of seconds

The following is an example of a duration declaration in a schema:
<xs:element name="period" type="xs:duration"/>

An element in the document might look like this:

<period>P5Y</period>

The example above indicates a period of five years.

Or it might look like this:

<period>P5Y2M10D</period>

The example above indicates a period of five years, two months, and 10 days.
Comment 1 Lin Zhu CLA 2007-03-15 01:08:53 EDT
Hi there,

I think you can use data type "string" to acquire the value of duration type, can you?

If you want to do some specific operations for duration type, Because BIRT do not support duration type, we have to treat it as a string even if the duration type is supported.

Thanks.
Lin
Comment 2 malcolm davis CLA 2007-03-15 12:59:20 EDT
"String" can be used to acquire anything XML related.  

However:
a.  The String" form of an XML Duration type has no meaning on a report.  
Users do not understand P5Y2M10D.

b.  The "String" cannot be used to do any duration type calculations.  
Calculating pay, total hours worked, duration of a project, etc…

c.  In every IT and commercial and XML data source I have touched, there has been a XML Duration.  I have seen Duration used at BellSouth, Fidelity Investments, Intuit, etc.  From an XML data source perspective, Duration is not a minor thing.

Some possible solutions:
a.  Time:  BIRT has a Time data type.  Using Time will depend on how the underlying Time type looks or can be used.  

b.  IBM’s ICU Lib:  BIRT is already uses and extends the ICU lib.  There may be an option in ICU.

c.  Add a Duration type to BIRT.  The Duration type would be beneficial to both XML and SQL worlds.  

d.  Java 5:  There is a XML Duration type in Java 5.  [Drawback:  If BIRT still needs to support JDK 1.4.

e.  JSR 310:  Supposedly, JSR 310 (Date and Time API) will address the Duration issue.  Yet, that is sometime in future.
http://jcp.org/en/jsr/detail?id=310
http://wiki.java.net/bin/view/Projects/DateTimeScope
http://wiki.java.net/bin/view/Projects/DateTimeDuration

g.  Other libs:  There are open source libs like Joda that support the concept of duration.  http://joda-time.sourceforge.net/key_duration.html

Thanks,
Malcolm
Comment 3 Gary Xue CLA 2007-03-23 18:45:49 EDT
We will need to add this data type to DTP/ODA in order for BIRT to be able to access it in external data sources. Transfer to DTP project for consideration.

JRE (since 1.5) does have javax.xml.datatype.Duration to represent the Duration type. 

Before BIRT and DTP add native support for this data type, you can read the duration type as String, and then parse it using a custom Javascript function in BIRT. BIRT does provide a DataTimeSpan Javascript object that makes it easier to work with time span data.
Comment 4 Linda Chan CLA 2007-03-24 01:12:20 EDT
Once BIRT supports duration, one can parse a string retrieved from the oda.xml driver, using a custom Javascript function in BIRT and map to BIRT's duration type.
Thus, adding support of duration data type in ODA interfaces should not be on the critical path here.  Even with such support in ODA, one still won't be able to format such data in a meaningful way in a report item, nor do computation of such data unless a duration type is supported by BIRT.  Having duration support in BIRT is the critical path and main enhancement, as described in comment #2.  
Comment 5 Gary Xue CLA 2007-03-26 16:41:32 EDT
We will look into introducing the Duration type in BIRT, and offer Javascript functions to facilitate calculation based on Duration. We'll like to base this data type on javax.xml.datatypes.Duration (or correponding JSR 310 data type if that gets implemented soon enough). This will be done in the next major release. BIRT 2.2 must run on JRE 1.4, which does not have Duration support. 

If your BIRT app is running on JRE 1.5 or later, you can in fact directly invoke the Java Duration class from Javascript expressions to help you perform conversion and duration calculations. Here is an example on how that can be done:

Suppose the XML data set has a column DURATION_COLUMN of type XML Duration. You will need to define and use that column as String in BIRT. You can however add that duration to a date/time column using Javascript expression like this:

 duration = Packages.javax.xml.datatype.DatatypeFactory.
                 newInstance().newDuration(row["DURATION_COLOMN"]);
 DateTimeSpan.addDate(row["DATE_COLUMN"], 
       duration.getYears(), duration.getMonths(), duration.getDays())
Comment 6 Lin Zhu CLA 2009-02-24 02:53:30 EST
As per latest discussion we will only introduce a set of script function to manipulate duration-formatted data.
Comment 7 Lin Zhu CLA 2009-03-05 03:32:52 EST
Introduce BirtDuration function under BIRT Function's category. Here we support the mothod as following method:
year( String lexicalDuration)
month(String lexicalDuration)
day(String lexicalDuration)
hour(String lexicalDuration)
minute(String lexicalDuration)
second(String lexicalDuration)
timeInMills(String lexicalDuration,DateTime startDate)
isLongerThan(String lexicalDuration1,String lexicalDuration2)
isShorterThan(String lexicalDuration1,String lexicalDuration2)

Fix it now.
Comment 8 Tianli Zhang CLA 2009-03-09 04:41:59 EDT
BIRTDuration functions are added and worked as expected, issue #267570 has been found during the general testing and the further testing is in Progress, so mark this bug as verified first. Verified build: 2.5.0 v20090309-0630.