merged from asterix_stabilization r408:544
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_temporal_fixes@545 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/data/events/tiny/event.adm b/asterix-app/data/events/tiny/event.adm
index 21fd7e7..5e9d4b3 100644
--- a/asterix-app/data/events/tiny/event.adm
+++ b/asterix-app/data/events/tiny/event.adm
@@ -5,8 +5,8 @@
"sponsoring_sigs": [ { "sig_id": 14, "chapter_name": "San Clemente" },
{ "sig_id": 14, "chapter_name": "Laguna Beach" } ],
"interest_keywords": {{ "art", "landscape", "nature", "vernissage" }},
- "start_time": datetime( "2011-02-23T18:00:00:000-08:00" ),
- "end_time": datetime( "2011-02-23T21:00:00:000-08:00" )
+ "start_time": datetime( "2011-02-23T18:00:00.000-08:00" ),
+ "end_time": datetime( "2011-02-23T21:00:00.000-08:00" )
}
{
"event_id": 941,
@@ -16,8 +16,8 @@
"sponsoring_sigs": [ { "sig_id": 31, "chapter_name": "Huntington Beach" } ],
"interest_keywords": {{ "scuba", "diving", "aquatics" }},
"price": 40.00,
- "start_time": datetime( "2010-10-16T09:00:00:000-08:00" ),
- "end_time": datetime( "2010-10-16T12:00:00:000-08:00" )
+ "start_time": datetime( "2010-10-16T09:00:00.000-08:00" ),
+ "end_time": datetime( "2010-10-16T12:00:00.000-08:00" )
}
{
"event_id": 1042,
@@ -26,7 +26,7 @@
"sponsoring_sigs": [ { "sig_id": 14, "chapter_name": "Laguna Beach" } ],
"interest_keywords": {{ "architecture", "photography" }},
"price": 10.00,
- "start_time": datetime( "2011-02-23T17:00:00:000-08:00" ),
- "end_time": datetime( "2011-02-23T19:00:00:000-08:00" )
+ "start_time": datetime( "2011-02-23T17:00:00.000-08:00" ),
+ "end_time": datetime( "2011-02-23T19:00:00.000-08:00" )
}
\ No newline at end of file
diff --git a/asterix-app/data/nontagged/allData.json b/asterix-app/data/nontagged/allData.json
index e70257a..5f7bf3b 100644
--- a/asterix-app/data/nontagged/allData.json
+++ b/asterix-app/data/nontagged/allData.json
@@ -1,2 +1,2 @@
-{ "id": 10, "name": string("Nancy"), "age": 32.5f, "salary": 12.000 ,"married": boolean("true"), "interests": {{"reading", "writing"}}, "children": ["Brad", "Scott"], "address": { "number": 8389, "street": "Hill St.", "city": "Mountain View" }, "dob": date("-2011-01-27"), "time": time("12:20:30Z"), "datetime": datetime("-1951-12-27T12:20:30"), "duration": duration("D10Y11M12DT10H50M30S"), "location2d": point("41.00,44.00"), "location3d": point3d("44.00,13.00,41.00"), "line" : line("10.1,11.1 10.2,11.2"), "polygon" : polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), "circle" : circle("10.1,11.1 10.2") }
+{ "id": 10, "name": string("Nancy"), "age": 32.5f, "salary": 12.000 ,"married": boolean("true"), "interests": {{"reading", "writing"}}, "children": ["Brad", "Scott"], "address": { "number": 8389, "street": "Hill St.", "city": "Mountain View" }, "dob": date("-2011-01-27"), "time": time("12:20:30Z"), "datetime": datetime("-1951-12-27T12:20:30"), "duration": duration("P10Y11M12DT10H50M30S"), "location2d": point("41.00,44.00"), "location3d": point3d("44.00,13.00,41.00"), "line" : line("10.1,11.1 10.2,11.2"), "polygon" : polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), "circle" : circle("10.1,11.1 10.2") }
diff --git a/asterix-app/data/nontagged/tempData.json b/asterix-app/data/nontagged/tempData.json
index 1fef3ab..a40a254 100644
--- a/asterix-app/data/nontagged/tempData.json
+++ b/asterix-app/data/nontagged/tempData.json
@@ -1,2 +1,2 @@
-{ "id": 10, "date": date("2011-01-27"), "time": time("12:20:30"), "datetime": datetime("1951-12-27T12:20:30"), "duration": duration("D30Y10M15DT10H30M50S"), "date2": date("2011-01-27-05:00"), "time2": time("12:20:30:999-05:00"), "datetime2": datetime("1951-12-27T12:20:30:250-08:45"), "duration2": duration("D10M15DT10H50S"), "date3": date("-2011-01-27-05:00"), "time3": time("12:20:30:999Z"), "datetime3": datetime("-1951-12-27T12:20:30:250-08:15"), "duration3": duration("-DT50S"), "date4": date("-2011-01-27Z"), "time4": time("12:20:30Z"), "datetime4": datetime("-1951-12-27T12:20:30:250Z"), "duration4": duration("-D10M"), "date5": date("2011-01-27"), "time5": time("12:20:30"), "datetime5": datetime("1951-12-27T12:20:30"), "duration5": duration("D30Y10M15DT10H30M50S") }
+{ "id": 10, "date": date("2011-01-27"), "time": time("12:20:30"), "datetime": datetime("1951-12-27T12:20:30"), "duration": duration("P30Y10M15DT10H30M50S"), "date2": date("2011-01-27"), "time2": time("12:20:30.999-05:00"), "datetime2": datetime("1951-12-27T12:20:30.250-08:45"), "duration2": duration("P10M15DT10H50S"), "date3": date("-2011-01-27"), "time3": time("12:20:30.999Z"), "datetime3": datetime("-1951-12-27T12:20:30.250-08:15"), "duration3": duration("-PT50S"), "date4": date("-2011-01-27"), "time4": time("12:20:30Z"), "datetime4": datetime("-1951-12-27T12:20:30.250Z"), "duration4": duration("-P10M"), "date5": date("2011-01-27"), "time5": time("12:20:30"), "datetime5": datetime("1951-12-27T12:20:30"), "duration5": duration("P30Y10M15DT10H30M50S") }
diff --git a/asterix-app/data/nontagged/tempData.txt b/asterix-app/data/nontagged/tempData.txt
index 6615812..0afeb6f 100644
--- a/asterix-app/data/nontagged/tempData.txt
+++ b/asterix-app/data/nontagged/tempData.txt
@@ -1,4 +1,4 @@
-10|date("2011-01-27")|time("12:20:30")|datetime("1951-12-27T12:20:30")|duration("D30Y10M15DT10H30M50S")
-20|date("2011-01-27-05:00")|time("12:20:30:999-05:00")|datetime("1951-12-27T12:20:30:250-08:45")|duration("D10M15DT10H50S")
-30|date("-2011-01-27-05:00")|time("12:20:30:999Z")|datetime("-1951-12-27T12:20:30:250-08:15")|duration("-DT50S")
-40|date("-2011-01-27Z")|time("12:20:30Z")|datetime("-1951-12-27T12:20:30:250Z")|duration("-D10M")
+10|date("2011-01-27")|time("12:20:30")|datetime("1951-12-27T12:20:30")|duration("P30Y10M15DT10H30M50S")
+20|date("2011-01-27")|time("12:20:30.999-05:00")|datetime("1951-12-27T12:20:30.250-08:45")|duration("P10M15DT10H50S")
+30|date("-2011-01-27")|time("12:20:30.999Z")|datetime("-1951-12-27T12:20:30.250-08:15")|duration("-PT50S")
+40|date("-2011-01-27")|time("12:20:30Z")|datetime("-1951-12-27T12:20:30.250Z")|duration("-P10M")
diff --git a/asterix-app/src/test/resources/aqljts/results/nested_01.adm b/asterix-app/src/test/resources/aqljts/results/nested_01.adm
index 54444c7..27de5c0 100644
--- a/asterix-app/src/test/resources/aqljts/results/nested_01.adm
+++ b/asterix-app/src/test/resources/aqljts/results/nested_01.adm
@@ -30,4 +30,4 @@
ARecordType:
field: t
AbstractCollectionType:
-ADateTime: { 2011-9-16:11:0:0:0:0:0 }
+ADateTime: { 2011-09-16T11:00:00.000Z }
diff --git a/asterix-app/src/test/resources/runtimets/queries/comparison/datetime_order.aql b/asterix-app/src/test/resources/runtimets/queries/comparison/datetime_order.aql
index 2e151ab..f2d8208 100644
--- a/asterix-app/src/test/resources/runtimets/queries/comparison/datetime_order.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/comparison/datetime_order.aql
@@ -11,7 +11,13 @@
let $dt3 := datetime("2005-01-01T00:00:00+04:00")
let $dt4 := datetime("2011-12-31T13:00:00-11:00")
let $dt5 := datetime("2012-04-06T00:00:00Z")
+let $dt6 := datetime("-1937-07-07T23:00:00+08:00")
+let $dt7 := datetime("-1600-03-01T00:00:00.384+06:00")
+let $dt8 := datetime("-1600-02-29T23:59:59.999Z")
+let $dt9 := datetime("2000-02-29T23:59:59.999Z")
+let $dt10 := datetime("2000-03-01T01:59:59.999+07:00")
+let $dt11 := datetime("-1600-03-01T00:00:00.384-06:00")
-for $dt in [$dt1, $dt2, $dt3, $dt4, $dt5]
+for $dt in [$dt1, $dt2, $dt3, $dt4, $dt5, $dt6, $dt7, $dt8, $dt9, $dt10, $dt11]
order by $dt
return $dt
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/comparison/datetime_tzeq.aql b/asterix-app/src/test/resources/runtimets/queries/comparison/datetime_tzeq.aql
index e38bdae..1a0bb52 100644
--- a/asterix-app/src/test/resources/runtimets/queries/comparison/datetime_tzeq.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/comparison/datetime_tzeq.aql
@@ -8,6 +8,10 @@
let $dt1 := datetime("2011-12-31T14:00:00-10:00")
let $dt2 := datetime("2012-01-01T00:00:00Z")
+let $dt3 := datetime("2000-03-01T02:00:00+04:00")
+let $dt4 := datetime("2000-02-29T22:00:00Z")
+let $r1 := $dt1 = $dt2
+let $r2 := $dt3 = $dt4
-return [$dt1 = $dt2]
\ No newline at end of file
+return { "result1": $r1,"result2": $r2 }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/date_01.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/date_01.aql
index c889627..9bbfb9d 100644
--- a/asterix-app/src/test/resources/runtimets/queries/constructor/date_01.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/date_01.aql
@@ -4,12 +4,14 @@
write output to nc1:"rttest/constructor_date_01.adm";
-let $c1 := date("2010-10-30+05:00")
-let $c2 := date("2010-10-30-10:15")
-let $c3 := date("1987-11-19")
-let $c4 := date("1987-11-19Z")
-let $c5 := date("-1987-11-19+08:30")
-let $c6 := date("0001-12-27")
-let $c7 := date("-1951-01-27-01:45")
-return {"date1": $c1, "date2": $c2, "date3": $c3, "date4": $c4, "date5": $c5, "date6": $c6, "date7": $c7}
+let $c1 := date("2010-10-30")
+let $c2 := date("1987-11-19")
+let $c3 := date("-1987-11-19")
+let $c4 := date("0001-12-27")
+let $c5 := date("-1951-12-27")
+let $c6 := date("-2043-11-19")
+let $c7 := date("-19280329")
+let $c8 := date("19280329")
+
+return {"date1": $c1, "date2": $c2, "date3": $c3, "date4": $c4, "date5": $c5, "date6": $c6, "date7": $c7, "date8": $c8}
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/datetime_01.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/datetime_01.aql
index 611feff..c4163d8 100644
--- a/asterix-app/src/test/resources/runtimets/queries/constructor/datetime_01.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/datetime_01.aql
@@ -1,13 +1,22 @@
+drop dataverse test if exists;
+create dataverse test;
use dataverse test;
write output to nc1:"rttest/constructor_datetime_01.adm";
-let $c1 := datetime("2010-10-30T10:50:56:999+05:45")
-let $c2 := datetime("2010-10-30T10:30:56:250-10:00")
-let $c3 := datetime("1987-11-19T09:20:00:200")
+let $c1 := datetime("2010-10-30T10:50:56.999+05:45")
+let $c2 := datetime("2010-10-30T10:30:56.250-10:00")
+let $c3 := datetime("1987-11-19T09:20:00.200Z")
let $c4 := datetime("1987-11-19T10:50:56Z")
-let $c5 := datetime("-1987-11-19T10:50:56:099-05:30")
-let $c6 := datetime("-0001-11-19T10:50:56:719Z")
-let $c7 := datetime("1951-12-27T12:20:15")
-return {"datetime1": $c1, "datetime2": $c2, "datetime3": $c3, "datetime4": $c4, "datetime5": $c5, "datetime6": $c6, "datetime7": $c7}
+let $c5 := datetime("-1987-11-19T10:50:56.099-05:30")
+let $c6 := datetime("-0001-11-19T10:50:56.719Z")
+let $c7 := datetime("1951-12-27T12:20:15Z")
+let $c8 := datetime("2043-11-19T10:50:56.719Z")
+let $c9 := datetime("-19280329T174937374-0630")
+let $c10 := datetime("-19280329T174937374+0630")
+let $c11 := datetime("-19280329T174937374")
+let $c12 := datetime("-19280329T174937374+0630")
+let $c13 := datetime("-19280329T17493737+0630")
+let $c14 := datetime("-19280301T05493737+0630")
+return {"datetime1": $c1, "datetime2": $c2, "datetime3": $c3, "datetime4": $c4, "datetime5": $c5, "datetime6": $c6, "datetime7": $c7, "datetime8": $c8, "datetime9": $c9, "datetime10": $c10, "datetime11": $c11, "datetime12": $c12, "datetime13": $c13, "datetime14": $c14}
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/duration_01.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/duration_01.aql
index 011996c..59a3634 100644
--- a/asterix-app/src/test/resources/runtimets/queries/constructor/duration_01.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/duration_01.aql
@@ -4,13 +4,17 @@
write output to nc1:"rttest/constructor_duration_01.adm";
-let $c1 := duration("D30Y10M25DT13H12M50S")
-let $c2 := duration("D25DT13H12M50S")
-let $c3 := duration("DT13H12M50S")
-let $c4 := duration("D30YT12MS")
-let $c5 := duration("DT13H")
-let $c6 := duration("-D30Y10M25DT13H12M50S")
-let $c7 := duration("-D25DT13H12M50S")
-let $c8 := duration("-DT13H50S")
-return {"duration1": $c1, "duration2": $c2, "duration3": $c3, "duration4": $c4, "duration5": $c5, "duration6": $c6, "duration7": $c7, "duration8": $c8}
+let $c1 := duration("P30Y10M25DT13H12M50S")
+let $c2 := duration("P25DT13H12M50S")
+let $c3 := duration("PT13H12M50S")
+let $c4 := duration("P30YT12MS")
+let $c5 := duration("PT13H")
+let $c6 := duration("-P30Y10M25DT13H12M50S")
+let $c7 := duration("-P25DT13H12M50S")
+let $c8 := duration("-PT13H50S")
+let $c9 := duration("P120D")
+let $c10 := duration("-P28M")
+let $c11 := duration("PT29M90.937S")
+let $c12 := duration("P300Y15M60DT300H98M482.435S")
+return {"duration1": $c1, "duration2": $c2, "duration3": $c3, "duration4": $c4, "duration5": $c5, "duration6": $c6, "duration7": $c7, "duration8": $c8, "duration9": $c9, "duration10": $c10, "duration11": $c11, "duration12": $c12}
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/time_01.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/time_01.aql
index caa90f0..4a040a1 100644
--- a/asterix-app/src/test/resources/runtimets/queries/constructor/time_01.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/time_01.aql
@@ -4,12 +4,16 @@
write output to nc1:"rttest/constructor_time_01.adm";
-let $c1 := time("10:50:56:200+05:00")
-let $c2 := time("10:50:56:200-10:15")
+let $c1 := time("10:50:56.200+05:00")
+let $c2 := time("10:50:56.200-10:15")
let $c3 := time("10:50:56")
-let $c4 := time("10:50:56:200Z")
-let $c5 := time("23:59:59:999-13:30")
-let $c6 := time("24:00:00:000+14:45")
-let $c7 := time("12:59:00:019-01:00")
-return {"time1": $c1, "time2": $c2, "time3": $c3, "time4": $c4, "time5": $c5, "time6": $c6, "time7": $c7}
+let $c4 := time("10:50:56.200Z")
+let $c5 := time("23:59:59.999-13:30")
+let $c6 := time("00:00:00.000+14:45")
+let $c7 := time("12:59:00.019-01:00")
+let $c8 := time("12:59:00.01-01:00")
+let $c9 := time("12:59:00.019-01:00")
+let $c10 := time("12590001-0100")
+let $c11 := time("125900019-0100")
+return {"time1": $c1, "time2": $c2, "time3": $c3, "time4": $c4, "time5": $c5, "time6": $c6, "time7": $c7, "time8": $c8, "time9": $c9, "time10": $c10, "time11": $c11}
diff --git a/asterix-app/src/test/resources/runtimets/results/comparison/datetime_order.adm b/asterix-app/src/test/resources/runtimets/results/comparison/datetime_order.adm
index 14f3ab1..21f8208 100644
--- a/asterix-app/src/test/resources/runtimets/results/comparison/datetime_order.adm
+++ b/asterix-app/src/test/resources/runtimets/results/comparison/datetime_order.adm
@@ -1,5 +1,11 @@
-datetime("2005-01-01T00:00:00:000+04:00")
-datetime("2012-01-01T00:00:00:000+00:00")
-datetime("2011-12-31T14:00:00:000-10:00")
-datetime("2011-12-31T13:00:00:000-11:00")
-datetime("2012-04-06T00:00:00:000+00:00")
+datetime("-1937-07-07T15:00:00.000Z")
+datetime("-1600-02-29T18:00:00.384Z")
+datetime("-1600-02-29T23:59:59.999Z")
+datetime("-1600-03-01T06:00:00.384Z")
+datetime("2000-02-29T18:59:59.999Z")
+datetime("2000-02-29T23:59:59.999Z")
+datetime("2004-12-31T20:00:00.000Z")
+datetime("2012-01-01T00:00:00.000Z")
+datetime("2012-01-01T00:00:00.000Z")
+datetime("2012-01-01T00:00:00.000Z")
+datetime("2012-04-06T00:00:00.000Z")
diff --git a/asterix-app/src/test/resources/runtimets/results/comparison/datetime_tzeq.adm b/asterix-app/src/test/resources/runtimets/results/comparison/datetime_tzeq.adm
index 5dc225e..167bafb 100644
--- a/asterix-app/src/test/resources/runtimets/results/comparison/datetime_tzeq.adm
+++ b/asterix-app/src/test/resources/runtimets/results/comparison/datetime_tzeq.adm
@@ -1 +1 @@
-[ true ]
+{ "result1": true, "result2": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/constructor/date_01.adm b/asterix-app/src/test/resources/runtimets/results/constructor/date_01.adm
index b0cb1e4..2a90c4d 100644
--- a/asterix-app/src/test/resources/runtimets/results/constructor/date_01.adm
+++ b/asterix-app/src/test/resources/runtimets/results/constructor/date_01.adm
@@ -1 +1 @@
-{ "date1": date("2010-10-30+05:00"), "date2": date("2010-10-30-10:15"), "date3": date("1987-11-19+00:00"), "date4": date("1987-11-19+00:00"), "date5": date("-1987-11-19+08:30"), "date6": date("0001-12-27+00:00"), "date7": date("-1951-01-27-01:45") }
\ No newline at end of file
+{ "date1": date("2010-10-30"), "date2": date("1987-11-19"), "date3": date("-1987-11-19"), "date4": date("0001-12-27"), "date5": date("-1951-12-27"), "date6": date("-2043-11-19"), "date7": date("-1928-03-29"), "date8": date("1928-03-29") }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/constructor/datetime_01.adm b/asterix-app/src/test/resources/runtimets/results/constructor/datetime_01.adm
index 30d2cdb..54e76c4 100644
--- a/asterix-app/src/test/resources/runtimets/results/constructor/datetime_01.adm
+++ b/asterix-app/src/test/resources/runtimets/results/constructor/datetime_01.adm
@@ -1 +1 @@
-{ "datetime1": datetime("2010-10-30T10:50:56:980+05:45"), "datetime2": datetime("2010-10-30T10:30:56:240-10:00"), "datetime3": datetime("1987-11-19T09:20:00:200+00:00"), "datetime4": datetime("1987-11-19T10:50:56:000+00:00"), "datetime5": datetime("-1987-11-19T10:50:56:080-05:30"), "datetime6": datetime("-0001-11-19T10:50:56:700+00:00"), "datetime7": datetime("1951-12-27T12:20:15:000+00:00") }
+{ "datetime1": datetime("2010-10-30T05:05:56.999Z"), "datetime2": datetime("2010-10-30T20:30:56.250Z"), "datetime3": datetime("1987-11-19T09:20:00.200Z"), "datetime4": datetime("1987-11-19T10:50:56.000Z"), "datetime5": datetime("-1987-11-19T16:20:56.099Z"), "datetime6": datetime("-0001-11-19T10:50:56.719Z"), "datetime7": datetime("1951-12-27T12:20:15.000Z"), "datetime8": datetime("2043-11-19T10:50:56.719Z"), "datetime9": datetime("-1928-03-30T00:19:37.374Z"), "datetime10": datetime("-1928-03-29T11:19:37.374Z"), "datetime11": datetime("-1928-03-29T17:49:37.374Z"), "datetime12": datetime("-1928-03-29T11:19:37.374Z"), "datetime13": datetime("-1928-03-29T11:19:37.370Z"), "datetime14": datetime("-1928-02-29T23:19:37.370Z") }
diff --git a/asterix-app/src/test/resources/runtimets/results/constructor/duration_01.adm b/asterix-app/src/test/resources/runtimets/results/constructor/duration_01.adm
index b80ed1a..3a9cbb7 100644
--- a/asterix-app/src/test/resources/runtimets/results/constructor/duration_01.adm
+++ b/asterix-app/src/test/resources/runtimets/results/constructor/duration_01.adm
@@ -1 +1 @@
-{ "duration1": duration("D30Y10M25DT13H12M50S"), "duration2": duration("D0Y0M25DT13H12M50S"), "duration3": duration("D0Y0M0DT13H12M50S"), "duration4": duration("D30Y0M0DT0H12M0S"), "duration5": duration("D0Y0M0DT13H0M0S"), "duration6": duration("-D30Y10M25DT13H12M50S"), "duration7": duration("-D0Y0M25DT13H12M50S"), "duration8": duration("-D0Y0M0DT13H0M50S") }
+{ "duration1": duration("P30Y10M25DT13H12M50S"), "duration2": duration("P25DT13H12M50S"), "duration3": duration("PT13H12M50S"), "duration4": duration("P30YT12M"), "duration5": duration("PT13H"), "duration6": duration("-P30Y10M25DT13H12M50S"), "duration7": duration("-P25DT13H12M50S"), "duration8": duration("-PT13H50S"), "duration9": duration("P120D"), "duration10": duration("-P2Y4M"), "duration11": duration("PT30M30.937S"), "duration12": duration("P301Y3M72DT13H46M2.435S") }
diff --git a/asterix-app/src/test/resources/runtimets/results/constructor/time_01.adm b/asterix-app/src/test/resources/runtimets/results/constructor/time_01.adm
index 2c932b5..ef6adc9 100644
--- a/asterix-app/src/test/resources/runtimets/results/constructor/time_01.adm
+++ b/asterix-app/src/test/resources/runtimets/results/constructor/time_01.adm
@@ -1 +1 @@
-{ "time1": time("10:50:56:200+05:00"), "time2": time("10:50:56:200-10:15"), "time3": time("10:50:56:000+00:00"), "time4": time("10:50:56:200+00:00"), "time5": time("23:59:59:980-13:30"), "time6": time("24:00:00:000+14:45"), "time7": time("12:59:00:000-01:00") }
+{ "time1": time("05:50:56.200Z"), "time2": time("21:05:56.200Z"), "time3": time("10:50:56.000Z"), "time4": time("10:50:56.200Z"), "time5": time("13:29:59.999Z"), "time6": time("09:15:00.000Z"), "time7": time("13:59:00.019Z"), "time8": time("13:59:00.010Z"), "time9": time("13:59:00.019Z"), "time10": time("13:59:00.010Z"), "time11": time("13:59:00.019Z") }
diff --git a/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01.adm b/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01.adm
index 3fad2e3..64aee7c 100644
--- a/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01.adm
+++ b/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01.adm
@@ -1 +1 @@
-{ "id": 10, "name": "Nancy", "age": 32.5f, "salary": 12.0d, "married": true, "interests": {{ "reading", "writing" }}, "children": [ "Brad", "Scott" ], "address": { "number": 8389, "street": "Hill St.", "city": "Mountain View" }, "dob": date("-2011-01-27+00:00"), "time": time("12:20:30:000+00:00"), "datetime": datetime("-1951-12-27T12:20:30:000+00:00"), "duration": duration("D10Y11M12DT10H50M30S"), "location2d": point("41.0,44.0"), "location3d": point3d("44.0,13.0,41.0"), "line": line("10.1,11.1 10.2,11.2"), "polygon": polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), "circle": circle("10.1,11.1 10.2") }
+{ "id": 10, "name": "Nancy", "age": 32.5f, "salary": 12.0d, "married": true, "interests": {{ "reading", "writing" }}, "children": [ "Brad", "Scott" ], "address": { "number": 8389, "street": "Hill St.", "city": "Mountain View" }, "dob": date("-2011-01-27"), "time": time("12:20:30.000Z"), "datetime": datetime("-1951-12-27T12:20:30.000Z"), "duration": duration("P10Y11M12DT10H50M30S"), "location2d": point("41.0,44.0"), "location3d": point3d("44.0,13.0,41.0"), "line": line("10.1,11.1 10.2,11.2"), "polygon": polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), "circle": circle("10.1,11.1 10.2") }
diff --git a/asterix-app/src/test/resources/runtimets/results/scan/temp_types_01.adm b/asterix-app/src/test/resources/runtimets/results/scan/temp_types_01.adm
index 013a0cb..4ad4f1c 100644
--- a/asterix-app/src/test/resources/runtimets/results/scan/temp_types_01.adm
+++ b/asterix-app/src/test/resources/runtimets/results/scan/temp_types_01.adm
@@ -1 +1 @@
-{ "id": 10, "date": date("2011-01-27+00:00"), "time": time("12:20:30:000+00:00"), "datetime": datetime("1951-12-27T12:20:30:000+00:00"), "duration": duration("D30Y10M15DT10H30M50S"), "date2": date("2011-01-27-05:00"), "time2": time("12:20:30:980-05:00"), "datetime2": datetime("1951-12-27T12:20:30:240-08:45"), "duration2": duration("D0Y10M15DT10H0M50S"), "date3": date("-2011-01-27-05:00"), "time3": time("12:20:30:980+00:00"), "datetime3": datetime("-1951-12-27T12:20:30:240-08:15"), "duration3": duration("-D0Y0M0DT0H0M50S"), "date4": date("-2011-01-27+00:00"), "time4": time("12:20:30:000+00:00"), "datetime4": datetime("-1951-12-27T12:20:30:240+00:00"), "duration4": duration("-D0Y10M0DT0H0M0S"), "date5": date("2011-01-27+00:00"), "time5": time("12:20:30:000+00:00"), "datetime5": datetime("1951-12-27T12:20:30:000+00:00"), "duration5": duration("D30Y10M15DT10H30M50S") }
\ No newline at end of file
+{ "id": 10, "date": date("2011-01-27"), "time": time("12:20:30.000Z"), "datetime": datetime("1951-12-27T12:20:30.000Z"), "duration": duration("P30Y10M15DT10H30M50S"), "date2": date("2011-01-27"), "time2": time("17:20:30.999Z"), "datetime2": datetime("1951-12-27T21:05:30.250Z"), "duration2": duration("P10M15DT10H50S"), "date3": date("-2011-01-27"), "time3": time("12:20:30.999Z"), "datetime3": datetime("-1951-12-27T20:35:30.250Z"), "duration3": duration("-PT50S"), "date4": date("-2011-01-27"), "time4": time("12:20:30.000Z"), "datetime4": datetime("-1951-12-27T12:20:30.250Z"), "duration4": duration("-P10M"), "date5": date("2011-01-27"), "time5": time("12:20:30.000Z"), "datetime5": datetime("1951-12-27T12:20:30.000Z"), "duration5": duration("P30Y10M15DT10H30M50S") }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/scan/temp_types_02.adm b/asterix-app/src/test/resources/runtimets/results/scan/temp_types_02.adm
index f87b1e5..f0b6815 100644
--- a/asterix-app/src/test/resources/runtimets/results/scan/temp_types_02.adm
+++ b/asterix-app/src/test/resources/runtimets/results/scan/temp_types_02.adm
@@ -1,4 +1,4 @@
-{ "id": 10, "date": date("2011-01-27+00:00"), "time": time("12:20:30:000+00:00"), "datetime": datetime("1951-12-27T12:20:30:000+00:00"), "duration": duration("D30Y10M15DT10H30M50S") }
-{ "id": 20, "date": date("2011-01-27-05:00"), "time": time("12:20:30:980-05:00"), "datetime": datetime("1951-12-27T12:20:30:240-08:45"), "duration": duration("D0Y10M15DT10H0M50S") }
-{ "id": 30, "date": date("-2011-01-27-05:00"), "time": time("12:20:30:980+00:00"), "datetime": datetime("-1951-12-27T12:20:30:240-08:15"), "duration": duration("-D0Y0M0DT0H0M50S") }
-{ "id": 40, "date": date("-2011-01-27+00:00"), "time": time("12:20:30:000+00:00"), "datetime": datetime("-1951-12-27T12:20:30:240+00:00"), "duration": duration("-D0Y10M0DT0H0M0S") }
+{ "id": 10, "date": date("2011-01-27"), "time": time("12:20:30.000Z"), "datetime": datetime("1951-12-27T12:20:30.000+00:00"), "duration": duration("P30Y10M15DT10H30M50S") }
+{ "id": 20, "date": date("2011-01-27"), "time": time("17:20:30.999Z"), "datetime": datetime("1951-12-27T12:20:30.240-08:45"), "duration": duration("P10M15DT10H50S") }
+{ "id": 30, "date": date("-2011-01-27"), "time": time("12:20:30.999Z"), "datetime": datetime("-1951-12-27T12:20:30.240-08:15"), "duration": duration("-PT50S") }
+{ "id": 40, "date": date("-2011-01-27"), "time": time("12:20:30.000Z"), "datetime": datetime("-1951-12-27T12:20:30.240+00:00"), "duration": duration("-P10M") }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/comparators/ADateTimeAscBinaryComparatorFactory.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/comparators/ADateTimeAscBinaryComparatorFactory.java
index b62c21a..2dd8785 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/comparators/ADateTimeAscBinaryComparatorFactory.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/comparators/ADateTimeAscBinaryComparatorFactory.java
@@ -1,6 +1,5 @@
package edu.uci.ics.asterix.dataflow.data.nontagged.comparators;
-import edu.uci.ics.asterix.om.base.AMutableDateTime;
import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
@@ -15,41 +14,27 @@
@Override
public IBinaryComparator createBinaryComparator() {
return new IBinaryComparator() {
-
- private AMutableDateTime dt1 = new AMutableDateTime(0, 0, 0, 0, 0, 0, 0, 0, 0);
- private AMutableDateTime dt2 = new AMutableDateTime(0, 0, 0, 0, 0, 0, 0, 0, 0);
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
- short year = (short) (((b1[s1] & 0xff) << 8) | b1[s1 + 1] & 0xff);
- int time = ((b1[s1 + 4] & 0xff) << 24) | ((b1[s1 + 5] & 0xff) << 16) | ((b1[s1 + 6] & 0xff) << 8)
- | (b1[s1 + 7] & 0xff);
- dt1.setValue(year >> 1, // year
- (year & 0x0001) * 8 + ((b1[s1 + 2] >>> 5) & 0x07), // month
- b1[s1 + 2] & 0x1f, // day
- (short) ((time) * 20 % 216000000 / 3600000), // hour
- (short) ((time) * 20 % 3600000 / 60000), // minutes
- (short) ((time) * 20 % 60000 / 1000), // seconds
- (short) ((time) * 20 % 1000), // milliseconds
- 0, // microseconds
- b1[s1 + 3]); // timezone
+ long chrononTime1 = getLong(b1, s1);
+ long chrononTime2 = getLong(b2, s2);
- year = (short) (((b2[s2] & 0xff) << 8) | b2[s2 + 1] & 0xff);
- time = ((b2[s2 + 4] & 0xff) << 24) | ((b2[s2 + 5] & 0xff) << 16) | ((b2[s2 + 6] & 0xff) << 8)
- | (b2[s2 + 7] & 0xff);
+ if (chrononTime1 > chrononTime2) {
+ return 1;
+ } else if (chrononTime1 < chrononTime2) {
+ return -1;
+ } else {
+ return 0;
+ }
+ }
- dt2.setValue(year >> 1, // year
- (year & 0x0001) * 8 + ((b2[s2 + 2] >>> 5) & 0x07), // month
- b2[s2 + 2] & 0x1f, // day
- (short) ((time) * 20 % 216000000 / 3600000), // hour
- (short) ((time) * 20 % 3600000 / 60000), // minutes
- (short) ((time) * 20 % 60000 / 1000), // seconds
- (short) ((time) * 20 % 1000), // milliseconds
- 0, // microseconds
- b2[s2 + 3]); // timezone
-
- return dt1.compare(dt2);
+ private long getLong(byte[] bytes, int start) {
+ return (((long) (bytes[start] & 0xff)) << 56) + (((long) (bytes[start + 1] & 0xff)) << 48)
+ + (((long) (bytes[start + 2] & 0xff)) << 40) + (((long) (bytes[start + 3] & 0xff)) << 32)
+ + (((long) (bytes[start + 4] & 0xff)) << 24) + (((long) (bytes[start + 5] & 0xff)) << 16)
+ + (((long) (bytes[start + 6] & 0xff)) << 8) + (((long) (bytes[start + 7] & 0xff)) << 0);
}
};
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java
index e9f887e..cd2b8c56 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java
@@ -2,13 +2,17 @@
import java.io.PrintStream;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.algebricks.data.IPrinter;
public class ADatePrinter implements IPrinter {
private static final long serialVersionUID = 1L;
+
+ private static long CHRONON_OF_DAY = 24 * 60 * 60 * 1000;
+
public static final ADatePrinter INSTANCE = new ADatePrinter();
@Override
@@ -18,11 +22,16 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- int year = AInt16SerializerDeserializer.getShort(b, s + 1) >> 1;
- int month = (AInt16SerializerDeserializer.getShort(b, s + 1) & 0x0001) * 8 + ((b[s + 3] >> 5) & 0x07);
- int day = b[s + 3] & 0x1f;
- byte timezone = b[s + 4];
- ps.format("date(\"" + (year < 0 ? "%+05d" : "%04d") + "-%02d-%02d%+03d:%02d\")", year, month, day,
- timezone / 4, timezone % 4 * ((timezone >= 0) ? 15 : -15));
+ long chrononTime = AInt32SerializerDeserializer.getInt(b, s + 1) * CHRONON_OF_DAY;
+
+ GregorianCalendarSystem calendar = GregorianCalendarSystem.getInstance();
+
+ int year = calendar.getYear(chrononTime);
+ int month = calendar.getMonthOfYear(chrononTime, year);
+
+ ps.print("date(\"");
+ ps.append(String.format(year < 0 ? "%05d" : "%04d", year)).append("-").append(String.format("%02d", month))
+ .append("-").append(String.format("%02d", calendar.getDayOfMonthYear(chrononTime, year, month)));
+ ps.print("\")");
}
}
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java
index e3999f1..fdd6b18 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java
@@ -1,13 +1,11 @@
package edu.uci.ics.asterix.dataflow.data.nontagged.printers;
-import java.io.IOException;
import java.io.PrintStream;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.algebricks.data.IPrinter;
-import edu.uci.ics.hyracks.algebricks.data.utils.WriteValueTools;
public class ADateTimePrinter implements IPrinter {
@@ -21,49 +19,20 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- int year = AInt16SerializerDeserializer.getShort(b, s + 1) >> 1;
- int month = (AInt16SerializerDeserializer.getShort(b, s + 1) & 0x0001) * 8 + ((b[s + 3] >> 5) & 0x07);
+ long chrononTime = AInt64SerializerDeserializer.getLong(b, s + 1);
- int day = b[s + 3] & 0x1f;
- byte timezone = b[s + 4];
+ GregorianCalendarSystem calendar = GregorianCalendarSystem.getInstance();
- int time = AInt32SerializerDeserializer.getInt(b, s + 5);
- // int msec = (time) * 20 % 1000;
- // int sec = (time) * 20 % 60000 / 1000;
- // int min = (time) * 20 % 3600000 / 60000;
- // int hour = (time) * 20 % 216000000 / 3600000;
+ int year = calendar.getYear(chrononTime);
+ int month = calendar.getMonthOfYear(chrononTime, year);
ps.print("datetime(\"");
- if (year < 0) {
- ps.print("-");
- }
- int y = Math.abs(year);
- if (y < 1000) {
- ps.print("0");
- }
- if (y < 100) {
- ps.print("0");
- }
- if (y < 10) {
- ps.print("0");
- }
- try {
- WriteValueTools.writeInt(y, ps);
- ps.print("-");
- if (month < 10) {
- ps.print("0");
- }
- WriteValueTools.writeInt(month, ps);
- ps.print("-");
- if (day < 10) {
- ps.print("0");
- }
- WriteValueTools.writeInt(day, ps);
- ps.print("T");
- } catch (IOException e) {
- throw new AlgebricksException(e);
- }
- ATimePrinter.printTime(time, timezone, ps);
+ ps.append(String.format(year < 0 ? "%05d" : "%04d", year)).append("-").append(String.format("%02d", month))
+ .append("-").append(String.format("%02d", calendar.getDayOfMonthYear(chrononTime, year, month)))
+ .append("T").append(String.format("%02d", calendar.getHourOfDay(chrononTime))).append(":")
+ .append(String.format("%02d", calendar.getMinOfHour(chrononTime))).append(":")
+ .append(String.format("%02d", calendar.getSecOfMin(chrononTime))).append(".")
+ .append(String.format("%03d", calendar.getMillisOfSec(chrononTime))).append("Z");
ps.print("\")");
}
}
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADurationPrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADurationPrinter.java
index 1c4e302..837c3db 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADurationPrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADurationPrinter.java
@@ -4,6 +4,8 @@
import java.io.PrintStream;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.algebricks.data.IPrinter;
import edu.uci.ics.hyracks.algebricks.data.utils.WriteValueTools;
@@ -12,6 +14,7 @@
private static final long serialVersionUID = 1L;
public static final ADurationPrinter INSTANCE = new ADurationPrinter();
+ private static final GregorianCalendarSystem gCalInstance = GregorianCalendarSystem.getInstance();
@Override
public void init() {
@@ -22,39 +25,60 @@
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
boolean positive = true;
int months = AInt32SerializerDeserializer.getInt(b, s + 1);
- int seconds = AInt32SerializerDeserializer.getInt(b, s + 5);
+ long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 5);
- if (months < 0 || seconds < 0) {
+ // set the negative flag. "||" is necessary in case that months field is not there (so it is 0)
+ if (months < 0 || milliseconds < 0) {
months *= -1;
- seconds *= -1;
+ milliseconds *= -1;
positive = false;
}
- int month = (int) (months % 12);
- int year = (int) (months / 12);
- int second = (int) (seconds % 60);
- int minute = (int) (seconds % 3600 / 60);
- int hour = (int) (seconds % (86400) / 3600);
- int day = (int) (seconds / (86400));
+ int month = gCalInstance.getDurationMonth(months);
+ int year = gCalInstance.getDurationYear(months);
+ int millisecond = gCalInstance.getDurationMillisecond(milliseconds);
+ int second = gCalInstance.getDurationSecond(milliseconds);
+ int minute = gCalInstance.getDurationMinute(milliseconds);
+ int hour = gCalInstance.getDurationHour(milliseconds);
+ int day = gCalInstance.getDurationDay(milliseconds);
ps.print("duration(\"");
if (!positive) {
ps.print("-");
}
try {
- ps.print("D");
- WriteValueTools.writeInt(year, ps);
- ps.print("Y");
- WriteValueTools.writeInt(month, ps);
- ps.print("M");
- WriteValueTools.writeInt(day, ps);
- ps.print("DT");
- WriteValueTools.writeInt(hour, ps);
- ps.print("H");
- WriteValueTools.writeInt(minute, ps);
- ps.print("M");
- WriteValueTools.writeInt(second, ps);
- ps.print("S\")");
+ ps.print("P");
+ if (year != 0) {
+ WriteValueTools.writeInt(year, ps);
+ ps.print("Y");
+ }
+ if (month != 0) {
+ WriteValueTools.writeInt(month, ps);
+ ps.print("M");
+ }
+ if (day != 0) {
+ WriteValueTools.writeInt(day, ps);
+ ps.print("D");
+ }
+ if (hour != 0 || minute != 0 || second != 0 || millisecond != 0)
+ ps.print("T");
+ if (hour != 0) {
+ WriteValueTools.writeInt(hour, ps);
+ ps.print("H");
+ }
+ if (minute != 0) {
+ WriteValueTools.writeInt(minute, ps);
+ ps.print("M");
+ }
+ if (second != 0 || millisecond != 0)
+ WriteValueTools.writeInt(second, ps);
+ if (millisecond > 0) {
+ ps.print(".");
+ WriteValueTools.writeInt(millisecond, ps);
+ }
+ if (second != 0 || millisecond != 0)
+ ps.print("S");
+ ps.print("\")");
} catch (IOException e) {
throw new AlgebricksException(e);
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java
index 7f687ea..bb11ae1 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java
@@ -1,12 +1,11 @@
package edu.uci.ics.asterix.dataflow.data.nontagged.printers;
-import java.io.IOException;
import java.io.PrintStream;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.algebricks.data.IPrinter;
-import edu.uci.ics.hyracks.algebricks.data.utils.WriteValueTools;
public class ATimePrinter implements IPrinter {
@@ -21,55 +20,15 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
int time = AInt32SerializerDeserializer.getInt(b, s + 1);
+ GregorianCalendarSystem calendar = GregorianCalendarSystem.getInstance();
ps.print("time(\"");
- int timezone = time >> 24;
- time -= (timezone << 24);
- printTime(time, timezone, ps);
+
+ ps.append(String.format("%02d", calendar.getHourOfDay(time))).append(":")
+ .append(String.format("%02d", calendar.getMinOfHour(time))).append(":")
+ .append(String.format("%02d", calendar.getSecOfMin(time))).append(".")
+ .append(String.format("%03d", calendar.getMillisOfSec(time))).append("Z");
+
ps.print("\")");
}
- final static void printTime(int time, int timezone, PrintStream ps) throws AlgebricksException {
- int msec = time * 20 % 1000;
- int sec = time * 20 % 60000 / 1000;
- int min = time * 20 % 3600000 / 60000;
- int hour = time * 20 % 216000000 / 3600000;
- try {
- if (hour < 10) {
- ps.print("0");
- }
- WriteValueTools.writeInt(hour, ps);
- ps.print(":");
- if (min < 10) {
- ps.print("0");
- }
- WriteValueTools.writeInt(min, ps);
- ps.print(":");
- if (sec < 10) {
- ps.print("0");
- }
- WriteValueTools.writeInt(sec, ps);
- ps.print(":");
- if (msec < 100) {
- ps.print("0");
- }
- if (msec < 10) {
- ps.print("0");
- }
- WriteValueTools.writeInt(msec, ps);
- ps.print(timezone >= 0 ? "+" : "-");
- int t1 = Math.abs(timezone / 4);
- if (t1 < 10) {
- ps.print("0");
- }
- WriteValueTools.writeInt(t1, ps);
- ps.print(":");
- int t2 = timezone % 4 * ((timezone >= 0) ? 15 : -15);
- if (t2 < 10) {
- ps.print("0");
- }
- WriteValueTools.writeInt(t2, ps);
- } catch (IOException e) {
- throw new AlgebricksException(e);
- }
- }
}
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinterFactory.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinterFactory.java
index 2603067..afafb89 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinterFactory.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinterFactory.java
@@ -3,8 +3,6 @@
import edu.uci.ics.hyracks.algebricks.data.IPrinter;
import edu.uci.ics.hyracks.algebricks.data.IPrinterFactory;
-
-
public class ATimePrinterFactory implements IPrinterFactory {
private static final long serialVersionUID = 1L;
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateSerializerDeserializer.java
index 6a0e8cd..64d8262 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateSerializerDeserializer.java
@@ -7,6 +7,9 @@
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
import edu.uci.ics.asterix.om.base.ADate;
import edu.uci.ics.asterix.om.base.AMutableDate;
+import edu.uci.ics.asterix.om.base.temporal.ADateAndTimeParser;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
+import edu.uci.ics.asterix.om.base.temporal.StringCharSequenceAccessor;
import edu.uci.ics.asterix.om.types.BuiltinType;
import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
@@ -14,15 +17,11 @@
public class ADateSerializerDeserializer implements ISerializerDeserializer<ADate> {
private static final long serialVersionUID = 1L;
- private short year;
- private byte monthAndDay;
public static final ADateSerializerDeserializer INSTANCE = new ADateSerializerDeserializer();
@SuppressWarnings("unchecked")
- private static ISerializerDeserializer<ADate> dateSerde = AqlSerializerDeserializerProvider.INSTANCE
+ private static final ISerializerDeserializer<ADate> dateSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.ADATE);
- private static AMutableDate aDate = new AMutableDate(0, 0, 0, 0);
- private static String errorMessage = " can not be an instance of date";
private ADateSerializerDeserializer() {
}
@@ -30,10 +29,7 @@
@Override
public ADate deserialize(DataInput in) throws HyracksDataException {
try {
- year = in.readShort();
- monthAndDay = in.readByte();
- return new ADate(year >> 1, (year & 0x0001) * 8 + ((monthAndDay >> 5) & 0x07), monthAndDay & 0x1f,
- in.readByte());
+ return new ADate(in.readInt());
} catch (IOException e) {
throw new HyracksDataException(e);
}
@@ -42,60 +38,29 @@
@Override
public void serialize(ADate instance, DataOutput out) throws HyracksDataException {
try {
- out.writeByte((byte) ((instance.getYear() << 1) >> 8));
- out.writeByte((byte) ((byte) ((instance.getYear() << 1) & 0x00ff) + (byte) (instance.getMonth() >> 3)));
- out.writeByte((byte) (((byte) (instance.getMonth() << 5)) | ((byte) instance.getDay())));
- out.writeByte((byte) instance.getTimeZone());
+ out.writeInt(instance.getChrononTimeInDays());
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
public static void parse(String date, DataOutput out) throws HyracksDataException {
- int offset = 0;
- boolean positive = true;
- byte timezonePart = 0;
- if (date.charAt(0) == '-') {
- positive = false;
- offset++;
+ AMutableDate aDate = new AMutableDate(0);
+
+ long chrononTimeInMs = 0;
+ try {
+ StringCharSequenceAccessor charAccessor = new StringCharSequenceAccessor();
+ charAccessor.reset(date, 0);
+ chrononTimeInMs = ADateAndTimeParser.parseDatePart(charAccessor, true);
+ } catch (Exception e) {
+ throw new HyracksDataException(e.getMessage());
}
- if (date.charAt(offset + 4) != '-' || date.charAt(offset + 7) != '-')
- throw new HyracksDataException(date + errorMessage);
- short year = Short.parseShort(date.substring(offset, offset + 4));
- short month = Short.parseShort(date.substring(offset + 5, offset + 7));
- short day = Short.parseShort(date.substring(offset + 8, offset + 10));
- short hour, minute;
- if (year < 0 || year > 9999 || month < 0 || month > 12 || day < 0 || day > 31)
- throw new HyracksDataException(date + errorMessage);
+ short temp = 0;
+ if (chrononTimeInMs < 0 && chrononTimeInMs % GregorianCalendarSystem.CHRONON_OF_DAY != 0)
+ temp = 1;
+ aDate.setValue((int) (chrononTimeInMs / GregorianCalendarSystem.CHRONON_OF_DAY) - temp);
- offset += 10;
-
- if (date.length() > offset) {
- if (date.charAt(offset) == 'Z')
- timezonePart = 0;
- else {
- if ((date.charAt(offset) != '+' && date.charAt(offset) != '-') || (date.charAt(offset + 3) != ':'))
- throw new HyracksDataException(date + errorMessage);
-
- hour = Short.parseShort(date.substring(offset + 1, offset + 3));
- minute = Short.parseShort(date.substring(offset + 4, offset + 6));
-
- if (hour < 0 || hour > 24 || (hour == 24 && minute != 0)
- || (minute != 0 && minute != 15 && minute != 30 && minute != 45))
- throw new HyracksDataException(date + errorMessage);
-
- if (date.charAt(offset) == '-')
- timezonePart = (byte) -((hour * 4) + minute / 15);
- else
- timezonePart = (byte) ((hour * 4) + minute / 15);
- }
-
- }
- if (!positive)
- year *= -1;
- aDate.setValue(year, month, day, timezonePart);
dateSerde.serialize(aDate, out);
}
-
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateTimeSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateTimeSerializerDeserializer.java
index c22da77..cf92eaa 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateTimeSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateTimeSerializerDeserializer.java
@@ -7,7 +7,10 @@
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
import edu.uci.ics.asterix.om.base.ADateTime;
import edu.uci.ics.asterix.om.base.AMutableDateTime;
+import edu.uci.ics.asterix.om.base.temporal.ADateAndTimeParser;
+import edu.uci.ics.asterix.om.base.temporal.StringCharSequenceAccessor;
import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
@@ -17,15 +20,10 @@
public static final ADateTimeSerializerDeserializer INSTANCE = new ADateTimeSerializerDeserializer();
@SuppressWarnings("unchecked")
- private static ISerializerDeserializer<ADateTime> datetimeSerde = AqlSerializerDeserializerProvider.INSTANCE
+ private static final ISerializerDeserializer<ADateTime> datetimeSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.ADATETIME);
- private static AMutableDateTime aDateTime = new AMutableDateTime(0, 0, 0, 0, 0, 0, 0, 0, 0);
- private static String errorMessage = " can not be an instance of datetime";
- private int time;
- private byte timezone;
- private short year;
- private byte monthAndDay;
+ private static final String errorMessage = "This can not be an instance of datetime";
private ADateTimeSerializerDeserializer() {
}
@@ -33,14 +31,7 @@
@Override
public ADateTime deserialize(DataInput in) throws HyracksDataException {
try {
- year = in.readShort();
- monthAndDay = in.readByte();
- timezone = in.readByte();
- time = in.readInt();
-
- return new ADateTime(year >> 1, (year & 0x0001) * 8 + ((monthAndDay >> 5) & 0x07), monthAndDay & 0x1f,
- (short) ((time) * 20 % 216000000 / 3600000), (short) ((time) * 20 % 3600000 / 60000),
- (short) ((time) * 20 % 60000 / 1000), (short) ((time) * 20 % 1000), (short) 0, timezone);
+ return new ADateTime(in.readLong());
} catch (IOException e) {
throw new HyracksDataException(e);
}
@@ -49,92 +40,39 @@
@Override
public void serialize(ADateTime instance, DataOutput out) throws HyracksDataException {
try {
- out.writeByte((byte) ((instance.getYear() << 1) >> 8));
- out.writeByte((byte) ((byte) ((instance.getYear() << 1) & 0x00ff) + (byte) (instance.getMonth() >> 3)));
- out.writeByte((byte) ((instance.getMonth() << 5) | (instance.getDay())));
- out.writeByte((byte) instance.getTimeZone());
- out.writeInt((((((instance.getHours() * 60) + instance.getMinutes()) * 60) + instance.getSeconds()) * 1000 + instance
- .getMilliseconds()) / 20);
+ out.writeLong(instance.getChrononTime());
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
public static void parse(String datetime, DataOutput out) throws HyracksDataException {
- boolean positive = true;
- int offset = 0;
- byte timezonePart = 0;
+ AMutableDateTime aDateTime = new AMutableDateTime(0L);
- if (datetime.charAt(offset) == '-') {
- offset++;
- positive = false;
+ long chrononTimeInMs = 0;
+ try {
+ StringCharSequenceAccessor charAccessor = new StringCharSequenceAccessor();
+ charAccessor.reset(datetime, 0);
+
+ // +1 if it is negative (-)
+ short timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
+
+ if (charAccessor.getCharAt(timeOffset + 10) != 'T' && charAccessor.getCharAt(timeOffset + 8) != 'T')
+ throw new AlgebricksException(errorMessage + ": missing T");
+
+ // if extended form 11, else 9
+ timeOffset += (charAccessor.getCharAt(timeOffset + 13) == ':') ? (short) (11) : (short) (9);
+
+ chrononTimeInMs = ADateAndTimeParser.parseDatePart(charAccessor, false);
+
+ charAccessor.reset(datetime, timeOffset);
+
+ chrononTimeInMs += ADateAndTimeParser.parseTimePart(charAccessor);
+ } catch (Exception e) {
+ throw new HyracksDataException(e.getMessage());
}
+ aDateTime.setValue(chrononTimeInMs);
- if (datetime.charAt(offset + 4) != '-' || datetime.charAt(offset + 7) != '-')
- throw new HyracksDataException(datetime + errorMessage);
-
- short year = Short.parseShort(datetime.substring(offset, offset + 4));
- short month = Short.parseShort(datetime.substring(offset + 5, offset + 7));
- short day = Short.parseShort(datetime.substring(offset + 8, offset + 10));
-
- if (year < 0 || year > 9999 || month < 0 || month > 12 || day < 0 || day > 31)
- throw new HyracksDataException(datetime + errorMessage);
-
- if (!positive)
- year *= -1;
-
- if (datetime.charAt(offset + 10) != 'T')
- throw new HyracksDataException(datetime + errorMessage);
-
- offset += 11;
-
- if (datetime.charAt(offset + 2) != ':' || datetime.charAt(offset + 5) != ':')
- throw new HyracksDataException(datetime + errorMessage);
-
- short hour = Short.parseShort(datetime.substring(offset, offset + 2));
- short minute = Short.parseShort(datetime.substring(offset + 3, offset + 5));
- short second = Short.parseShort(datetime.substring(offset + 6, offset + 8));
- short msecond = 0;
-
- if (datetime.length() > offset + 8 && datetime.charAt(offset + 8) == ':') {
- msecond = Short.parseShort(datetime.substring(offset + 9, offset + 12));
- if (hour < 0 || hour > 24 || minute < 0 || minute > 59 || second < 0 || second > 59 || msecond < 0
- || msecond > 999 || (hour == 24 && (minute != 0 || second != 0 || msecond != 0)))
- throw new HyracksDataException(datetime + errorMessage);
- offset += 12;
- } else {
- if (hour < 0 || hour > 24 || minute < 0 || minute > 59 || second < 0 || second > 59
- || (hour == 24 && (minute != 0 || second != 0)))
- throw new HyracksDataException(datetime + errorMessage);
- offset += 8;
- }
-
- short timezoneHour = 0, timezoneMinute = 0;
- if (datetime.length() > offset) {
- if (datetime.charAt(offset) == 'Z')
- timezonePart = 0;
- else {
- if ((datetime.charAt(offset) != '+' && datetime.charAt(offset) != '-')
- || (datetime.charAt(offset + 3) != ':'))
- throw new HyracksDataException(datetime + errorMessage);
-
- timezoneHour = Short.parseShort(datetime.substring(offset + 1, offset + 3));
- timezoneMinute = Short.parseShort(datetime.substring(offset + 4, offset + 6));
-
- if (timezoneHour < 0
- || timezoneHour > 24
- || (timezoneHour == 24 && timezoneMinute != 0)
- || (timezoneMinute != 0 && timezoneMinute != 15 && timezoneMinute != 30 && timezoneMinute != 45))
- throw new HyracksDataException(datetime + errorMessage);
-
- if (datetime.charAt(offset) == '-')
- timezonePart = (byte) -((timezoneHour * 4) + timezoneMinute / 15);
- else
- timezonePart = (byte) ((timezoneHour * 4) + timezoneMinute / 15);
- }
-
- }
- aDateTime.setValue(year, month, day, hour, minute, second, msecond, 0, timezonePart);
datetimeSerde.serialize(aDateTime, out);
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADurationSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADurationSerializerDeserializer.java
index 134eed6..77d6f28 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADurationSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADurationSerializerDeserializer.java
@@ -7,6 +7,8 @@
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
import edu.uci.ics.asterix.om.base.ADuration;
import edu.uci.ics.asterix.om.base.AMutableDuration;
+import edu.uci.ics.asterix.om.base.temporal.ADurationParser;
+import edu.uci.ics.asterix.om.base.temporal.StringCharSequenceAccessor;
import edu.uci.ics.asterix.om.types.BuiltinType;
import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
@@ -16,12 +18,9 @@
private static final long serialVersionUID = 1L;
public static final ADurationSerializerDeserializer INSTANCE = new ADurationSerializerDeserializer();
-
- private static AMutableDuration aDuration = new AMutableDuration(0, 0);
@SuppressWarnings("unchecked")
- private static ISerializerDeserializer<ADuration> durationSerde = AqlSerializerDeserializerProvider.INSTANCE
+ private static final ISerializerDeserializer<ADuration> durationSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.ADURATION);
- private static String errorMessage = " can not be an instance of duration";
private ADurationSerializerDeserializer() {
}
@@ -29,7 +28,7 @@
@Override
public ADuration deserialize(DataInput in) throws HyracksDataException {
try {
- return new ADuration(in.readInt(), in.readInt());
+ return new ADuration(in.readInt(), in.readLong());
} catch (IOException e) {
throw new HyracksDataException(e);
}
@@ -39,7 +38,7 @@
public void serialize(ADuration instance, DataOutput out) throws HyracksDataException {
try {
out.writeInt(instance.getMonths());
- out.writeInt(instance.getSeconds());
+ out.writeLong(instance.getMilliseconds());
} catch (IOException e) {
throw new HyracksDataException(e);
}
@@ -47,119 +46,14 @@
public static void parse(String duration, DataOutput out) throws HyracksDataException {
try {
- boolean positive = true;
- int offset = 0;
- int value = 0, hour = 0, minute = 0, second = 0, year = 0, month = 0, day = 0;
- boolean isYear = true, isMonth = true, isDay = true, isHour = true, isMinute = true, isSecond = true;
- boolean isTime = false;
- boolean timeItem = true;
- if (duration.charAt(offset) == '-') {
- offset++;
- positive = false;
- }
+ AMutableDuration aDuration = new AMutableDuration(0, 0);
+ StringCharSequenceAccessor charAccessor = new StringCharSequenceAccessor();
+ charAccessor.reset(duration, 0);
+ ADurationParser.parse(charAccessor, aDuration);
- if (duration.charAt(offset++) != 'D')
- throw new HyracksDataException(duration + errorMessage);
-
- for (; offset < duration.length(); offset++) {
- if (duration.charAt(offset) >= '0' && duration.charAt(offset) <= '9')
- value = value * 10 + duration.charAt(offset) - '0';
- else {
- switch (duration.charAt(offset)) {
- case 'Y':
- if (isYear) {
- year = value;
- isYear = false;
- } else
- throw new HyracksDataException(duration + errorMessage);
- break;
- case 'M':
- if (!isTime) {
- if (isMonth) {
- if (value < 0 || value > 11)
- throw new HyracksDataException(duration + errorMessage);
- else {
- month = value;
- isMonth = false;
- }
- } else
- throw new HyracksDataException(duration + errorMessage);
- } else if (isMinute) {
- if (value < 0 || value > 59)
- throw new HyracksDataException(duration + errorMessage);
- else {
- minute = value;
- isMinute = false;
- timeItem = false;
- }
- } else
- throw new HyracksDataException(duration + errorMessage);
- break;
- case 'D':
- if (isDay) {
- if (value < 0 || value > 30)
- throw new HyracksDataException(duration + errorMessage);
- else {
- day = value;
- isDay = false;
- }
- } else
- throw new HyracksDataException(duration + errorMessage);
- break;
- case 'T':
- if (!isTime) {
- isTime = true;
- timeItem = true;
- } else
- throw new HyracksDataException(duration + errorMessage);
- break;
-
- case 'H':
- if (isHour) {
- if (value < 0 || value > 23)
- throw new HyracksDataException(duration + errorMessage);
- else {
- hour = value;
- isHour = false;
- timeItem = false;
- }
- } else
- throw new HyracksDataException(duration + errorMessage);
- break;
- case 'S':
- if (isSecond) {
- if (value < 0 || value > 59)
- throw new HyracksDataException(duration + errorMessage);
- else {
- second = value;
- isSecond = false;
- timeItem = false;
- }
- } else
- throw new HyracksDataException(duration + errorMessage);
- break;
- default:
- throw new HyracksDataException(duration + errorMessage);
-
- }
- value = 0;
- }
- }
-
- if (isTime && timeItem)
- throw new HyracksDataException(duration + errorMessage);
-
- if (isYear && isMonth && isDay && !isTime)
- throw new HyracksDataException(duration + errorMessage);
-
- if (positive)
- aDuration.setValue(year * 12 + month, day * 24 * 3600 + 3600 * hour + 60 * minute + second);
- else
- aDuration.setValue(-1 * (year * 12 + month), -1
- * (day * 24 * 3600 + 3600 * hour + 60 * minute + second));
durationSerde.serialize(aDuration, out);
- } catch (HyracksDataException e) {
- throw new HyracksDataException(duration + errorMessage);
+ } catch (Exception e) {
+ throw new HyracksDataException(e.getMessage());
}
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ATimeSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ATimeSerializerDeserializer.java
index 1d4fe07..7fe99c3 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ATimeSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ATimeSerializerDeserializer.java
@@ -7,6 +7,8 @@
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
import edu.uci.ics.asterix.om.base.AMutableTime;
import edu.uci.ics.asterix.om.base.ATime;
+import edu.uci.ics.asterix.om.base.temporal.ADateAndTimeParser;
+import edu.uci.ics.asterix.om.base.temporal.StringCharSequenceAccessor;
import edu.uci.ics.asterix.om.types.BuiltinType;
import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
@@ -18,12 +20,8 @@
public static final ATimeSerializerDeserializer INSTANCE = new ATimeSerializerDeserializer();
@SuppressWarnings("unchecked")
- private static ISerializerDeserializer<ATime> timeSerde = AqlSerializerDeserializerProvider.INSTANCE
+ private static final ISerializerDeserializer<ATime> timeSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.ATIME);
- private static AMutableTime aTime = new AMutableTime(0, 0, 0, 0, 0, 0);
- private static String errorMessage = " can not be an instance of time";
-
- private int time, timezone;
private ATimeSerializerDeserializer() {
}
@@ -31,12 +29,8 @@
@Override
public ATime deserialize(DataInput in) throws HyracksDataException {
try {
- time = in.readInt();
- timezone = time >> 24;
- time -= (timezone << 24);
- return new ATime((short) ((time << 8 >> 8) * 20 % 216000000 / 3600000),
- (short) ((time << 8 >> 8) * 20 % 3600000 / 60000), (short) ((time << 8 >> 8) * 20 % 60000 / 1000),
- (short) ((time << 8 >> 8) * 20 % 1000), (short) 0, timezone);
+ return new ATime(in.readInt());
+
} catch (IOException e) {
throw new HyracksDataException(e);
}
@@ -45,84 +39,28 @@
@Override
public void serialize(ATime instance, DataOutput out) throws HyracksDataException {
try {
- time = instance.getTimeZone();
- time = time << 24;
- time = time
- + ((((((instance.getHours() * 60) + instance.getMinutes()) * 60) + instance.getSeconds()) * 1000 + instance
- .getMilliseconds()) / 20);
- out.writeInt(time);
+ out.writeInt(instance.getChrononTime());
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
- public static final void serialize(short hour, short minute, short second, short msecond, byte timeZone,
- DataOutput out) throws HyracksDataException {
- try {
- int time = timeZone;
- time = time << 24;
- time = time + ((((((hour * 60) + minute) * 60) + second) * 1000 + msecond) / 20);
- out.writeInt(time);
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
-
public static void parse(String time, DataOutput out) throws HyracksDataException {
+ AMutableTime aTime = new AMutableTime(0);
+ int chrononTimeInMs;
+
try {
- byte timezonePart = 0;
- int offset = 0;
- if (time.charAt(offset + 2) != ':' || time.charAt(offset + 5) != ':')
- throw new HyracksDataException(time + errorMessage);
-
- short hour = Short.parseShort(time.substring(offset, offset + 2));
- short minute = Short.parseShort(time.substring(offset + 3, offset + 5));
- short second = Short.parseShort(time.substring(offset + 6, offset + 8));
- short msecond = 0;
- if (time.length() > offset + 8 && time.charAt(offset + 8) == ':') {
- msecond = Short.parseShort(time.substring(offset + 9, offset + 12));
- if (hour < 0 || hour > 24 || minute < 0 || minute > 59 || second < 0 || second > 59 || msecond < 0
- || msecond > 999 || (hour == 24 && (minute != 0 || second != 0 || msecond != 0)))
- throw new HyracksDataException(time + errorMessage);
- offset += 12;
- } else {
- if (hour < 0 || hour > 24 || minute < 0 || minute > 59 || second < 0 || second > 59
- || (hour == 24 && (minute != 0 || second != 0)))
- throw new HyracksDataException(time + errorMessage);
- offset += 8;
- }
-
- short timezoneHour = 0, timezoneMinute = 0;
- if (time.length() > offset) {
- if (time.charAt(offset) == 'Z')
- timezonePart = 0;
- else {
- if ((time.charAt(offset) != '+' && time.charAt(offset) != '-') || (time.charAt(offset + 3) != ':'))
- throw new HyracksDataException(time + errorMessage);
-
- timezoneHour = Short.parseShort(time.substring(offset + 1, offset + 3));
- timezoneMinute = Short.parseShort(time.substring(offset + 4, offset + 6));
-
- if (timezoneHour < 0
- || timezoneHour > 24
- || (timezoneHour == 24 && timezoneMinute != 0)
- || (timezoneMinute != 0 && timezoneMinute != 15 && timezoneMinute != 30 && timezoneMinute != 45))
- throw new HyracksDataException(time + errorMessage);
-
- if (time.charAt(offset) == '-')
- timezonePart = (byte) -((timezoneHour * 4) + timezoneMinute / 15);
- else
- timezonePart = (byte) ((timezoneHour * 4) + timezoneMinute / 15);
- }
-
- }
-
- aTime.setValue(hour, minute, second, msecond, 0, timezonePart);
-
- timeSerde.serialize(aTime, out);
- } catch (HyracksDataException e) {
- throw new HyracksDataException(time + errorMessage);
+ StringCharSequenceAccessor charAccessor = new StringCharSequenceAccessor();
+ charAccessor.reset(time, 0);
+ chrononTimeInMs = ADateAndTimeParser.parseTimePart(charAccessor);
+ } catch (Exception e) {
+ throw new HyracksDataException(e.getMessage());
}
+
+ aTime.setValue(chrononTimeInMs);
+
+ timeSerde.serialize(aTime, out);
}
+
}
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
index f60c908..06d2a96 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
@@ -1,38 +1,25 @@
package edu.uci.ics.asterix.om.base;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
import edu.uci.ics.asterix.om.types.BuiltinType;
import edu.uci.ics.asterix.om.types.IAType;
import edu.uci.ics.asterix.om.visitors.IOMVisitor;
+/**
+ * ADate type represents dates in a gregorian calendar system.
+ */
public class ADate implements IAObject {
- protected int day;
- protected int month;
- protected int year;
- protected int timezone;
+ /**
+ * the number of full calendar days since the 1970-01-01 represented by the date value.
+ */
+ protected int chrononTimeInDay;
- public ADate(int year, int month, int day, int timezone) {
- this.day = day;
- this.month = month;
- this.year = year;
- this.timezone = timezone;
- }
+ private static long CHRONON_OF_DAY = 24 * 60 * 60 * 1000;
- public int getDay() {
- return day;
- }
-
- public int getMonth() {
- return month;
- }
-
- public int getTimeZone() {
- return timezone;
- }
-
- public int getYear() {
- return year;
+ public ADate(int chrononTimeInDay) {
+ this.chrononTimeInDay = chrononTimeInDay;
}
public IAType getType() {
@@ -43,14 +30,13 @@
if (!(o instanceof ADate)) {
return false;
} else {
- ADate d = (ADate) o;
- return d.getDay() == day && d.getMonth() == month && d.getYear() == year && d.getTimeZone() == timezone;
+ return ((ADate) o).chrononTimeInDay == this.chrononTimeInDay;
}
}
@Override
public int hashCode() {
- return ((year * 31 + month) * 31 + day) * 31 + timezone;
+ return chrononTimeInDay;
}
@Override
@@ -70,6 +56,15 @@
@Override
public String toString() {
- return "ADate: { " + year + "-" + month + "-" + day + ":" + timezone + " }";
+ StringBuilder sbder = new StringBuilder();
+ sbder.append("ADate: { ");
+ GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(
+ chrononTimeInDay * CHRONON_OF_DAY, 0, sbder, GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.DAY);
+ sbder.append(" }");
+ return sbder.toString();
+ }
+
+ public int getChrononTimeInDays() {
+ return chrononTimeInDay;
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
index e300d78..38835cf 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
@@ -1,73 +1,39 @@
package edu.uci.ics.asterix.om.base;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
import edu.uci.ics.asterix.om.types.BuiltinType;
import edu.uci.ics.asterix.om.types.IAType;
import edu.uci.ics.asterix.om.visitors.IOMVisitor;
+/**
+ * ADateTime type represents the timestamp values.
+ * <p/>
+ * An ADateTime value contains the following time fields:<br/>
+ * - year;<br/>
+ * - month;<br/>
+ * - day;<br/>
+ * - hour; <br/>
+ * - minute; <br/>
+ * - second; <br/>
+ * - millisecond. <br/>
+ * By default, an ADateTime value is a UTC time value, i.e., there is no timezone information maintained. However user can use the timezone based AQL function to convert a UTC time to a timezone-embedded time.
+ * <p/>
+ * And the string representation of an ADateTime value follows the ISO8601 standard, in the following format:<br/>
+ * [+|-]YYYY-MM-DDThh:mm:ss.xxxZ
+ * <p/>
+ * Internally, an ADateTime value is stored as the number of milliseconds elapsed since 1970-01-01T00:00:00.000Z (also called chronon time). Functions to convert between a string representation of an ADateTime and its chronon time are implemented in {@link GregorianCalendarSystem}.
+ * <p/>
+ */
public class ADateTime implements IAObject {
- private static final int[] NUM_DAYS_IN_MONTH = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+ /**
+ * Represent the time interval as milliseconds since 1970-01-01T00:00:00.000Z.
+ */
+ protected long chrononTime;
- protected int day;
- protected int hour;
- protected int minutes;
- protected int month;
- protected int seconds;
- protected int timezone;
- protected int year;
- protected int milliseconds;
- protected int microseconds;
-
- public ADateTime(int year, int month, int day, int hour, int minutes, int seconds, int timezone) {
- this.year = year;
- this.month = month;
- this.day = day;
- this.hour = hour;
- this.minutes = minutes;
- this.seconds = seconds;
- this.timezone = timezone;
- }
-
- public ADateTime(int year, int month, int day, int hour, int minutes, int seconds, int milliseconds,
- int microseconds, int timezone) {
- this.year = year;
- this.month = month;
- this.day = day;
- this.hour = hour;
- this.minutes = minutes;
- this.seconds = seconds;
- this.milliseconds = milliseconds;
- this.microseconds = microseconds;
- this.timezone = timezone;
- }
-
- public int getDay() {
- return day;
- }
-
- public int getHours() {
- return hour;
- }
-
- public int getMinutes() {
- return minutes;
- }
-
- public int getMonth() {
- return month;
- }
-
- public int getSeconds() {
- return seconds;
- }
-
- public int getTimeZone() {
- return timezone;
- }
-
- public int getYear() {
- return year;
+ public ADateTime(long chrononTime) {
+ this.chrononTime = chrononTime;
}
@Override
@@ -75,125 +41,33 @@
return BuiltinType.ADATETIME;
}
- public int getMicroseconds() {
- return microseconds;
- }
-
- public int getMilliseconds() {
- return milliseconds;
- }
-
public int compare(Object o) {
if (!(o instanceof ADateTime)) {
return -1;
}
ADateTime d = (ADateTime) o;
- if (timezone != d.getTimeZone()) {
- AMutableDateTime dt1 = new AMutableDateTime(year, month, day, hour, minutes, seconds, milliseconds,
- microseconds, timezone);
- AMutableDateTime dt2 = new AMutableDateTime(d.getYear(), d.getMonth(), d.getDay(), d.getHours(),
- d.getMinutes(), d.getSeconds(), d.getMilliseconds(), d.getMicroseconds(), d.getTimeZone());
- dt1.convertToUTC();
- dt2.convertToUTC();
-
- return dt1.tzEqualCompare(dt2);
-
- }
-
- return tzEqualCompare(d);
- }
-
- protected void convertToUTC() {
- short tzMin = (short) ((timezone % 4) * 15);
- short tzHr = (short) (timezone / 4);
- minutes -= tzMin;
- if (minutes >= 60) {
- minutes %= 60;
- hour += 1;
- }
- hour -= tzHr;
- if (hour >= 24) {
- hour %= 24;
- day += 1;
- }
- if (isLeapYear(year) && month == 2) {
- if (day >= 29) {
- day %= 29;
- month += 1;
- }
+ if (this.chrononTime > d.chrononTime) {
+ return 1;
+ } else if (this.chrononTime < d.chrononTime) {
+ return -1;
} else {
- if (day >= NUM_DAYS_IN_MONTH[month - 1]) {
- day %= NUM_DAYS_IN_MONTH[month - 1];
- month += 1;
- }
+ return 0;
}
-
- if (month >= 12) {
- month %= 12;
- year += 1;
- }
- timezone = 0;
-
- }
-
- protected static boolean isLeapYear(int year) {
- if (year % 400 == 0) {
- return true;
- } else if (year % 100 == 0) {
- return false;
- } else if (year % 4 == 0) {
- return true;
- } else {
- return false;
- }
- }
-
- // comparison that assumes the timezones are the same!
- protected int tzEqualCompare(ADateTime d) {
- if (year != d.getYear()) {
- return year - d.getYear();
- }
- if (month != d.getMonth()) {
- return month - d.getMonth();
- }
- if (day != d.getDay()) {
- return day - d.getDay();
- }
- if (hour != d.getHours()) {
- return hour - d.getHours();
- }
- if (minutes != d.getMinutes()) {
- return minutes - d.getMinutes();
- }
- if (seconds != d.getSeconds()) {
- return seconds - d.getSeconds();
- }
- if (milliseconds != d.getMilliseconds()) {
- return milliseconds - d.getMilliseconds();
- }
- if (microseconds != d.getMicroseconds()) {
- return microseconds - d.getMicroseconds();
- }
-
- return 0;
}
public boolean equals(Object o) {
if (!(o instanceof ADateTime)) {
return false;
} else {
- ADateTime d = (ADateTime) o;
- return d.getMicroseconds() == microseconds && d.getMilliseconds() == milliseconds
- && d.getSeconds() == seconds && d.getMinutes() == minutes && d.getHours() == hour
- && d.getDay() == day && d.getMonth() == month && d.getYear() == year && d.getTimeZone() == timezone;
+ ADateTime t = (ADateTime) o;
+ return t.chrononTime == this.chrononTime;
}
}
@Override
public int hashCode() {
- return (((((((year * 31 + month) * 31 + day) * 31 + timezone) * 31 + hour) * 31 + minutes) * 31 + seconds) * 31 + milliseconds)
- * 31 + microseconds;
+ return (int) (chrononTime ^ (chrononTime >>> 32));
}
@Override
@@ -213,8 +87,16 @@
@Override
public String toString() {
- return "ADateTime: { " + year + "-" + month + "-" + day + ":" + hour + ":" + minutes + ":" + seconds + ":"
- + milliseconds + ":" + microseconds + ":" + timezone + " }";
+ StringBuilder sbder = new StringBuilder();
+ sbder.append("ADateTime: { ");
+ GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(chrononTime, 0, sbder,
+ GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND);
+ sbder.append(" }");
+ return sbder.toString();
+ }
+
+ public long getChrononTime() {
+ return chrononTime;
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADuration.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADuration.java
index 6f8064e..1f9044b 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADuration.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADuration.java
@@ -1,26 +1,53 @@
package edu.uci.ics.asterix.om.base;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
import edu.uci.ics.asterix.om.types.BuiltinType;
import edu.uci.ics.asterix.om.types.IAType;
import edu.uci.ics.asterix.om.visitors.IOMVisitor;
+/**
+ * ADuration type represents time duration (unanchored time length) values.
+ * <p/>
+ * An ADuration value may contain the same fields as the {@link ADateTime}: <br/>
+ * - year;<br/>
+ * - month;<br/>
+ * - day;<br/>
+ * - hour; <br/>
+ * - minute; <br/>
+ * - second; <br/>
+ * - millisecond. <br/>
+ * Compared with {@link ADateTime}, a field in a duration value does not have the limited domain requirement. A duration field is valid as far as the value of the field is an integer.
+ * </p>
+ * We also support negative durations, which is not specified by ISO 8601, but has been
+ * supported by XML spec to enable the arithmetic operations between time instances.
+ * <p/>
+ * Internally, an ADuration value is stored as two fields: an integer field as the number of months for the YEAR and MONTH fields, and a long integer field as the number of milliseconds for the other fields.
+ * <p/>
+ */
public class ADuration implements IAObject {
- protected int months;
- protected int seconds;
+ /**
+ * number of full months represented by the year-month part
+ */
+ protected int chrononInMonth;
- public ADuration(int months, int seconds) {
- this.months = months;
- this.seconds = seconds;
+ /**
+ * number of milliseconds represented by the part other than the year and month
+ */
+ protected long chrononInMillisecond;
+
+ public ADuration(int months, long seconds) {
+ this.chrononInMonth = months;
+ this.chrononInMillisecond = seconds;
}
public int getMonths() {
- return months;
+ return chrononInMonth;
}
- public int getSeconds() {
- return seconds;
+ public long getMilliseconds() {
+ return chrononInMillisecond;
}
@Override
@@ -34,13 +61,13 @@
return false;
} else {
ADuration d = (ADuration) o;
- return d.getMonths() == months && d.getSeconds() == seconds;
+ return d.getMonths() == chrononInMonth && d.getMilliseconds() == chrononInMillisecond;
}
}
@Override
public int hashCode() {
- return months * 31 + seconds;
+ return (int) (chrononInMonth ^ (chrononInMillisecond) ^ (chrononInMillisecond >>> 32));
}
@Override
@@ -58,4 +85,13 @@
return hashCode();
}
+ @Override
+ public String toString() {
+ StringBuilder sbder = new StringBuilder();
+ sbder.append("ADuration: {");
+ GregorianCalendarSystem.getInstance().getDurationExtendStringRepWithTimezoneUntilField(chrononInMillisecond, chrononInMonth, sbder);
+ sbder.append(" }");
+ return sbder.toString();
+ }
+
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDate.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDate.java
index 78a87b8..f6a8e2d 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDate.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDate.java
@@ -2,15 +2,12 @@
public class AMutableDate extends ADate {
- public AMutableDate(int year, int month, int day, int timezone) {
- super(year, month, day, timezone);
+ public AMutableDate(int chrononTimeInDays) {
+ super(chrononTimeInDays);
}
- public void setValue(int year, int month, int day, int timezone) {
- this.year = year;
- this.month = month;
- this.day = day;
- this.timezone = timezone;
+ public void setValue(int chrononTimeInDays) {
+ this.chrononTimeInDay = chrononTimeInDays;
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDateTime.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDateTime.java
index 01e30a2..88553b0 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDateTime.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDateTime.java
@@ -2,22 +2,12 @@
public class AMutableDateTime extends ADateTime {
- public AMutableDateTime(int year, int month, int day, int hour, int minutes, int seconds, int milliseconds,
- int microseconds, int timezone) {
- super(year, month, day, hour, minutes, seconds, milliseconds, microseconds, timezone);
+ public AMutableDateTime(long chrononTime) {
+ super(chrononTime);
}
- public void setValue(int year, int month, int day, int hour, int minutes, int seconds, int milliseconds,
- int microseconds, int timezone) {
- this.year = year;
- this.month = month;
- this.day = day;
- this.hour = hour;
- this.minutes = minutes;
- this.seconds = seconds;
- this.milliseconds = milliseconds;
- this.microseconds = microseconds;
- this.timezone = timezone;
+ public void setValue(long chrononTime) {
+ this.chrononTime = chrononTime;
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDuration.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDuration.java
index f776817..367d529 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDuration.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableDuration.java
@@ -2,13 +2,13 @@
public class AMutableDuration extends ADuration {
- public AMutableDuration(int months, int seconds) {
- super(months, seconds);
+ public AMutableDuration(int months, long milliseconds) {
+ super(months, milliseconds);
}
- public void setValue(int months, int seconds) {
- this.months = months;
- this.seconds = seconds;
+ public void setValue(int months, long milliseconds) {
+ this.chrononInMonth = months;
+ this.chrononInMillisecond = milliseconds;
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableTime.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableTime.java
index a23b8e3..d6b7858 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableTime.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AMutableTime.java
@@ -2,16 +2,12 @@
public class AMutableTime extends ATime {
- public AMutableTime(int hour, int minutes, int seconds, int milliseconds, int microseconds, int timezone) {
- super(hour, minutes, seconds, milliseconds, microseconds, timezone);
+ public AMutableTime(int timeInMillisec) {
+ super(timeInMillisec);
}
- public void setValue(int hour, int minutes, int seconds, int milliseconds, int microseconds, int timezone) {
- this.hour = hour;
- this.minutes = minutes;
- this.seconds = seconds;
- this.milliseconds = milliseconds;
- this.timezone = timezone;
+ public void setValue(int timeInMillisec) {
+ this.chrononTime = timeInMillisec;
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
index f948ffc..0ce7d99 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
@@ -1,49 +1,20 @@
package edu.uci.ics.asterix.om.base;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
import edu.uci.ics.asterix.om.types.BuiltinType;
import edu.uci.ics.asterix.om.types.IAType;
import edu.uci.ics.asterix.om.visitors.IOMVisitor;
public class ATime implements IAObject {
- protected int hour;
- protected int minutes;
- protected int seconds;
- protected int timezone;
- protected int milliseconds;
- protected int microseconds;
+ /**
+ * number of milliseconds since the beginning of a day represented by this time value
+ */
+ protected int chrononTime;
- public ATime(int hour, int minutes, int seconds, int timezone) {
- this.hour = hour;
- this.minutes = minutes;
- this.seconds = seconds;
- this.timezone = timezone;
- }
-
- public ATime(int hour, int minutes, int seconds, int milliseconds, int microseconds, int timezone) {
- this.hour = hour;
- this.minutes = minutes;
- this.seconds = seconds;
- this.milliseconds = milliseconds;
- this.microseconds = microseconds;
- this.timezone = timezone;
- }
-
- public int getHours() {
- return hour;
- }
-
- public int getMinutes() {
- return minutes;
- }
-
- public int getSeconds() {
- return seconds;
- }
-
- public int getTimeZone() {
- return timezone;
+ public ATime(int chrononTime) {
+ this.chrononTime = chrononTime;
}
@Override
@@ -51,29 +22,36 @@
return BuiltinType.ATIME;
}
- public int getMicroseconds() {
- return microseconds;
- }
+ public int compare(Object o) {
+ if (!(o instanceof ATime)) {
+ return -1;
+ }
- public int getMilliseconds() {
- return milliseconds;
+ ATime d = (ATime) o;
+ if (this.chrononTime > d.chrononTime) {
+ return 1;
+ } else if (this.chrononTime < d.chrononTime) {
+ return -1;
+ } else {
+ return 0;
+ }
}
@Override
public boolean equals(Object o) {
+
if (!(o instanceof ATime)) {
return false;
} else {
ATime t = (ATime) o;
- return t.getMicroseconds() == microseconds && t.getMilliseconds() == milliseconds
- && t.getSeconds() == seconds && t.getMinutes() == minutes && t.getHours() == hour
- && t.getTimeZone() == timezone;
+ return t.chrononTime == this.chrononTime;
+
}
}
@Override
public int hashCode() {
- return ((((timezone * 31 + hour) * 31 + minutes) * 31 + seconds) * 31 + milliseconds) * 31 + microseconds;
+ return chrononTime;
}
@Override
@@ -93,7 +71,17 @@
@Override
public String toString() {
- return "ATime: { " + hour + ":" + minutes + ":" + seconds + ":" + milliseconds + ":" + microseconds + ":"
- + timezone + " }";
+ StringBuilder sbder = new StringBuilder();
+ sbder.append("ATime: { ");
+ GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(chrononTime, 0, sbder,
+ GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND);
+ sbder.append(" }");
+ return sbder.toString();
+
}
+
+ public int getChrononTime() {
+ return chrononTime;
+ }
+
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADateAndTimeParser.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADateAndTimeParser.java
new file mode 100644
index 0000000..28eb898
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADateAndTimeParser.java
@@ -0,0 +1,244 @@
+package edu.uci.ics.asterix.om.base.temporal;
+
+public class ADateAndTimeParser {
+
+ private static final GregorianCalendarSystem gCalInstance = GregorianCalendarSystem.getInstance();
+
+ private static final String dateErrorMessage = "Wrong date format!";
+ private static final String timeErrorMessage = "Wrong time format!";
+
+ /**
+ * Parse the given char sequence as a date string, and return the milliseconds represented by the date.
+ *
+ * @param charAccessor
+ * accessor for the char sequence
+ * @param isDateOnly
+ * indicating whether it is a single date string, or it is the date part of a datetime string
+ * @param errorMessage
+ * @return
+ * @throws Exception
+ */
+ public static <T> long parseDatePart(ICharSequenceAccessor<T> charAccessor, boolean isDateOnly) throws Exception {
+
+ int length = charAccessor.getLength();
+ int offset = 0;
+
+ int year = 0, month = 0, day = 0;
+ boolean positive = true;
+
+ boolean isExtendedForm = false;
+
+ if (charAccessor.getCharAt(offset) == '-') {
+ offset++;
+ positive = false;
+ }
+
+ if ((isDateOnly) && charAccessor.getCharAt(offset + 4) == '-' || (!isDateOnly)
+ && charAccessor.getCharAt(offset + 13) == ':')
+ isExtendedForm = true;
+
+ if (isExtendedForm)
+ if (charAccessor.getCharAt(offset + 4) != '-' || charAccessor.getCharAt(offset + 7) != '-')
+ throw new Exception(dateErrorMessage);
+
+ // year
+ for (int i = 0; i < 4; i++) {
+ if (charAccessor.getCharAt(offset + i) >= '0' && charAccessor.getCharAt(offset + i) <= '9') {
+ year = year * 10 + charAccessor.getCharAt(offset + i) - '0';
+ } else {
+ throw new Exception(dateErrorMessage);
+ }
+ }
+
+ if (year < GregorianCalendarSystem.FIELD_MINS[GregorianCalendarSystem.Fields.YEAR.ordinal()]
+ || year > GregorianCalendarSystem.FIELD_MAXS[GregorianCalendarSystem.Fields.YEAR.ordinal()]) {
+ throw new Exception(dateErrorMessage + ": year " + year);
+ }
+
+ offset += (isExtendedForm) ? 5 : 4;
+
+ // month
+ for (int i = 0; i < 2; i++) {
+ if ((charAccessor.getCharAt(offset + i) >= '0' && charAccessor.getCharAt(offset + i) <= '9')) {
+ month = month * 10 + charAccessor.getCharAt(offset + i) - '0';
+ } else {
+ throw new Exception(dateErrorMessage);
+ }
+ }
+
+ if (month < GregorianCalendarSystem.FIELD_MINS[GregorianCalendarSystem.Fields.MONTH.ordinal()]
+ || month > GregorianCalendarSystem.FIELD_MAXS[GregorianCalendarSystem.Fields.MONTH.ordinal()]) {
+ throw new Exception(dateErrorMessage + ": month " + month);
+ }
+ offset += (isExtendedForm) ? 3 : 2;
+
+ // day
+ for (int i = 0; i < 2; i++) {
+ if ((charAccessor.getCharAt(offset + i) >= '0' && charAccessor.getCharAt(offset + i) <= '9')) {
+ day = day * 10 + charAccessor.getCharAt(offset + i) - '0';
+ } else {
+ throw new Exception(dateErrorMessage);
+ }
+ }
+
+ if (day < GregorianCalendarSystem.FIELD_MINS[GregorianCalendarSystem.Fields.DAY.ordinal()]
+ || day > GregorianCalendarSystem.FIELD_MAXS[GregorianCalendarSystem.Fields.DAY.ordinal()]) {
+ throw new Exception(dateErrorMessage + ": day " + day);
+ }
+
+ offset += 2;
+
+ if (!positive)
+ year *= -1;
+
+ if (isDateOnly && length > offset) {
+ throw new Exception(dateErrorMessage);
+ }
+ return gCalInstance.getChronon(year, month, day, 0, 0, 0, 0, 0);
+ }
+
+ /**
+ * Parse the given char sequence as a time string, and return the milliseconds represented by the time.
+ *
+ * @param charAccessor
+ * @return
+ * @throws Exception
+ */
+ public static <T> int parseTimePart(ICharSequenceAccessor<T> charAccessor) throws Exception {
+
+ int length = charAccessor.getLength();
+ int offset = 0;
+
+ int hour = 0, min = 0, sec = 0, millis = 0;
+ int timezone = 0;
+
+ boolean isExtendedForm = false;
+ if (charAccessor.getCharAt(offset + 2) == ':') {
+ isExtendedForm = true;
+ }
+
+ if (isExtendedForm && (charAccessor.getCharAt(offset + 2) != ':' || charAccessor.getCharAt(offset + 5) != ':'))
+ throw new Exception(timeErrorMessage);
+
+ // hour
+ for (int i = 0; i < 2; i++) {
+ if ((charAccessor.getCharAt(offset + i) >= '0' && charAccessor.getCharAt(offset + i) <= '9')) {
+ hour = hour * 10 + charAccessor.getCharAt(offset + i) - '0';
+ } else {
+ throw new Exception(timeErrorMessage);
+ }
+ }
+
+ if (hour < GregorianCalendarSystem.FIELD_MINS[GregorianCalendarSystem.Fields.HOUR.ordinal()]
+ || hour > GregorianCalendarSystem.FIELD_MAXS[GregorianCalendarSystem.Fields.HOUR.ordinal()]) {
+ throw new Exception(timeErrorMessage + ": hour " + hour);
+ }
+
+ offset += (isExtendedForm) ? 3 : 2;
+
+ // minute
+ for (int i = 0; i < 2; i++) {
+ if ((charAccessor.getCharAt(offset + i) >= '0' && charAccessor.getCharAt(offset + i) <= '9')) {
+ min = min * 10 + charAccessor.getCharAt(offset + i) - '0';
+ } else {
+ throw new Exception(timeErrorMessage);
+ }
+ }
+
+ if (min < GregorianCalendarSystem.FIELD_MINS[GregorianCalendarSystem.Fields.MINUTE.ordinal()]
+ || min > GregorianCalendarSystem.FIELD_MAXS[GregorianCalendarSystem.Fields.MINUTE.ordinal()]) {
+ throw new Exception(timeErrorMessage + ": min " + min);
+ }
+
+ offset += (isExtendedForm) ? 3 : 2;
+
+ // second
+ for (int i = 0; i < 2; i++) {
+ if ((charAccessor.getCharAt(offset + i) >= '0' && charAccessor.getCharAt(offset + i) <= '9')) {
+ sec = sec * 10 + charAccessor.getCharAt(offset + i) - '0';
+ } else {
+ throw new Exception(timeErrorMessage);
+ }
+ }
+
+ if (sec < GregorianCalendarSystem.FIELD_MINS[GregorianCalendarSystem.Fields.SECOND.ordinal()]
+ || sec > GregorianCalendarSystem.FIELD_MAXS[GregorianCalendarSystem.Fields.SECOND.ordinal()]) {
+ throw new Exception(timeErrorMessage + ": sec " + sec);
+ }
+
+ offset += 2;
+
+ if ((isExtendedForm && length > offset && charAccessor.getCharAt(offset) == '.')
+ || (!isExtendedForm && length > offset)) {
+
+ offset += (isExtendedForm) ? 1 : 0;
+ int i = 0;
+ for (; i < 3 && offset + i < length; i++) {
+ if (charAccessor.getCharAt(offset + i) >= '0' && charAccessor.getCharAt(offset + i) <= '9') {
+ millis = millis * 10 + charAccessor.getCharAt(offset + i) - '0';
+ } else {
+ break;
+ }
+ }
+
+ offset += i;
+
+ for (; i < 3; i++) {
+ millis = millis * 10;
+ }
+
+ // error is thrown if more than three digits are seen for the millisecond part
+ if (charAccessor.getCharAt(offset) >= '0' && charAccessor.getCharAt(offset) <= '9') {
+ throw new Exception("Wrong format of time instance: too many fields for millisecond.");
+ }
+ }
+
+ if (length > offset) {
+ if (charAccessor.getCharAt(offset) != 'Z') {
+ if ((charAccessor.getCharAt(offset) != '+' && charAccessor.getCharAt(offset) != '-')
+ || (isExtendedForm && charAccessor.getCharAt(offset + 3) != ':'))
+ throw new Exception(timeErrorMessage);
+
+ short timezoneHour = 0;
+ short timezoneMinute = 0;
+
+ for (int i = 0; i < 2; i++) {
+ if ((charAccessor.getCharAt(offset + 1 + i) >= '0' && charAccessor.getCharAt(offset + 1 + i) <= '9'))
+ timezoneHour = (short) (timezoneHour * 10 + charAccessor.getCharAt(offset + 1 + i) - '0');
+ else
+ throw new Exception(timeErrorMessage);
+
+ }
+
+ if (timezoneHour < GregorianCalendarSystem.TIMEZONE_HOUR_MIN
+ || timezoneHour > GregorianCalendarSystem.TIMEZONE_HOUR_MAX) {
+ throw new Exception(timeErrorMessage + ": time zone hour " + timezoneHour);
+ }
+
+ int temp_offset = (isExtendedForm) ? 1 : 0;
+
+ for (int i = 0; i < 2; i++) {
+ if ((charAccessor.getCharAt(offset + temp_offset + 3 + i) >= '0' && charAccessor.getCharAt(offset
+ + temp_offset + 3 + i) <= '9'))
+ timezoneMinute = (short) (timezoneMinute * 10
+ + charAccessor.getCharAt(offset + temp_offset + 3 + i) - '0');
+ else
+ throw new Exception(timeErrorMessage);
+ }
+
+ if (timezoneMinute < GregorianCalendarSystem.TIMEZONE_MIN_MIN
+ || timezoneMinute > GregorianCalendarSystem.TIMEZONE_MIN_MAX) {
+ throw new Exception(timeErrorMessage + ": time zone minute " + timezoneMinute);
+ }
+
+ if (charAccessor.getCharAt(offset) == '-')
+ timezone = (byte) -((timezoneHour * 4) + timezoneMinute / 15);
+ else
+ timezone = (byte) ((timezoneHour * 4) + timezoneMinute / 15);
+
+ }
+ }
+
+ return gCalInstance.getChronon(hour, min, sec, millis, timezone);
+ }
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADurationParser.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADurationParser.java
new file mode 100644
index 0000000..c6bed37
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADurationParser.java
@@ -0,0 +1,125 @@
+package edu.uci.ics.asterix.om.base.temporal;
+
+import edu.uci.ics.asterix.om.base.AMutableDuration;
+
+public class ADurationParser {
+
+ private enum State {
+ NOTHING_READ,
+ YEAR,
+ MONTH,
+ DAY,
+ TIME,
+ HOUR,
+ MIN,
+ MILLISEC,
+ SEC;
+ };
+
+ private static final String errorMessage = "This can not be an instance of duration";
+
+ public static <T> void parse(ICharSequenceAccessor<T> charAccessor, AMutableDuration aDuration) throws Exception {
+
+ boolean positive = true;
+ int offset = 0;
+ int value = 0, hour = 0, minute = 0, second = 0, millisecond = 0, year = 0, month = 0, day = 0;
+ State state = State.NOTHING_READ;
+
+ if (charAccessor.getCharAt(offset) == '-') {
+ offset++;
+ positive = false;
+ }
+
+ if (charAccessor.getCharAt(offset++) != 'P')
+ throw new Exception(errorMessage);
+
+ for (; offset < charAccessor.getLength(); offset++) {
+ if (charAccessor.getCharAt(offset) >= '0' && charAccessor.getCharAt(offset) <= '9')
+ // accumulate the digit fields
+ value = value * 10 + charAccessor.getCharAt(offset) - '0';
+ else {
+ switch (charAccessor.getCharAt(offset)) {
+ case 'Y':
+ if (state.compareTo(State.YEAR) < 0) {
+ year = value;
+ state = State.YEAR;
+ } else
+ throw new Exception(errorMessage);
+ break;
+ case 'M':
+ if (state.compareTo(State.TIME) < 0) {
+ if (state.compareTo(State.MONTH) < 0) {
+ month = value;
+ state = State.MONTH;
+ } else
+ throw new Exception(errorMessage);
+ } else if (state.compareTo(State.MIN) < 0) {
+ minute = value;
+ state = State.MIN;
+ } else
+ throw new Exception(errorMessage);
+ break;
+ case 'D':
+ if (state.compareTo(State.DAY) < 0) {
+ day = value;
+ state = State.DAY;
+ } else
+ throw new Exception(errorMessage);
+ break;
+ case 'T':
+ if (state.compareTo(State.TIME) < 0) {
+ state = State.TIME;
+ } else
+ throw new Exception(errorMessage);
+ break;
+
+ case 'H':
+ if (state.compareTo(State.HOUR) < 0) {
+ hour = value;
+ state = State.HOUR;
+ } else
+ throw new Exception(errorMessage);
+ break;
+ case '.':
+ if (state.compareTo(State.MILLISEC) < 0) {
+ int i = 1;
+ for (; offset + i < charAccessor.getLength(); i++) {
+ if (charAccessor.getCharAt(offset + i) >= '0' && charAccessor.getCharAt(offset + i) <= '9') {
+ if (i < 4)
+ millisecond = millisecond * 10 + (charAccessor.getCharAt(offset + i) - '0');
+ else
+ throw new Exception(errorMessage);
+ } else
+ break;
+ }
+ offset += i;
+ state = State.MILLISEC;
+ } else
+ throw new Exception(errorMessage);
+ case 'S':
+ if (state.compareTo(State.SEC) < 0) {
+ second = value;
+ state = State.SEC;
+ } else
+ throw new Exception(errorMessage);
+ break;
+ default:
+ throw new Exception(errorMessage);
+
+ }
+ value = 0;
+ }
+ }
+
+ if (state.compareTo(State.TIME) == 0)
+ throw new Exception(errorMessage);
+
+ short temp = 1;
+ if (!positive)
+ temp = -1;
+
+ aDuration.setValue(temp * (year * 12 + month), temp
+ * (day * 24 * 3600 * 1000L + 3600 * 1000L * hour + 60 * minute * 1000L + second * 1000L + millisecond));
+
+ }
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ByteArrayCharSequenceAccessor.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ByteArrayCharSequenceAccessor.java
new file mode 100644
index 0000000..cae6275
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ByteArrayCharSequenceAccessor.java
@@ -0,0 +1,26 @@
+package edu.uci.ics.asterix.om.base.temporal;
+
+public class ByteArrayCharSequenceAccessor implements ICharSequenceAccessor<Byte[]> {
+
+ private byte[] string;
+ private int offset;
+ private int beginOffset;
+
+ @Override
+ public char getCharAt(int index) {
+ return (char) (string[index + offset + beginOffset]);
+ }
+
+ /* The offset is the position of the first letter in the byte array */
+ public void reset(byte[] obj, int beginOffset, int offset) {
+ string = obj;
+ this.offset = offset;
+ this.beginOffset = beginOffset;
+ }
+
+ @Override
+ public int getLength() {
+ return ((string[beginOffset - 2] & 0xff) << 8) + ((string[beginOffset - 1] & 0xff) << 0) - offset;
+ }
+
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java
new file mode 100644
index 0000000..0655ccf
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java
@@ -0,0 +1,706 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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.
+ *
+ * Joda API (http://joda-time.sourceforge.net/) is under the protection of:
+ *
+ * Copyright 2001-2005 Stephen Colebourne
+ *
+ * Licensed 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 edu.uci.ics.asterix.om.base.temporal;
+
+/**
+ * A simple implementation of the Gregorian calendar system.
+ * <p/>
+ */
+public class GregorianCalendarSystem implements ICalendarSystem {
+
+ public enum Fields {
+ YEAR,
+ MONTH,
+ DAY,
+ HOUR,
+ MINUTE,
+ SECOND,
+ MILLISECOND
+ };
+
+ //public static final int YEAR = 0, MONTH = 1, DAY = 2, HOUR = 3, MINUTE = 4, SECOND = 5, MILLISECOND = 6;
+
+ public static final int[] DAYS_OF_MONTH_ORDI = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+ public static final int[] DAYS_OF_MONTH_LEAP = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+ public static final int[] DAYS_SINCE_MONTH_BEGIN_ORDI = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
+
+ public static final int CHRONON_OF_SECOND = 1000;
+ public static final int CHRONON_OF_MINUTE = 60 * CHRONON_OF_SECOND;
+ public static final int CHRONON_OF_HOUR = 60 * CHRONON_OF_MINUTE;
+ public static final long CHRONON_OF_DAY = 24 * CHRONON_OF_HOUR;
+
+ /**
+ * Minimum feasible value of each field
+ */
+ public static final int[] FIELD_MINS = { Integer.MIN_VALUE, // year
+ 1, // month
+ 1, // day
+ 0, // hour
+ 0, // minute
+ 0, // second
+ 0 // millisecond
+ };
+
+ public static final int[] FIELD_MAXS = { Integer.MAX_VALUE, // year
+ 12, // month
+ 31, // day
+ 23, // hour
+ 59, // minute
+ 59, // second
+ 999 // millisecond
+ };
+
+ public static final int TIMEZONE_HOUR_MIN = -12, TIMEZONE_HOUR_MAX = 14, TIMEZONE_MIN_MIN = -60,
+ TIMEZONE_MIN_MAX = 60;
+
+ /**
+ * From Joda API: GregorianChronology.java
+ */
+ private static final long CHRONON_OF_YEAR = (long) (365.2425 * CHRONON_OF_DAY);
+
+ /**
+ * From Joda API: GregorianChronology.java
+ */
+ private static final int DAYS_0000_TO_1970 = 719527;
+
+ private static final GregorianCalendarSystem instance = new GregorianCalendarSystem();
+
+ private GregorianCalendarSystem() {
+ }
+
+ public static GregorianCalendarSystem getInstance() {
+ return instance;
+ }
+
+ /**
+ * Check whether the given date time value is a valid date time following the gregorian calendar system.
+ *
+ * @param fields
+ * @return
+ */
+ public boolean validate(int year, int month, int day, int hour, int min, int sec, int millis) {
+ // Check whether each field is within the value domain
+ if (year < FIELD_MINS[0] || year > FIELD_MAXS[0])
+ return false;
+ if (month < FIELD_MINS[1] || month > FIELD_MAXS[1])
+ return false;
+ if (day < FIELD_MINS[2] || day > FIELD_MAXS[2])
+ return false;
+ if (hour < FIELD_MINS[3] || hour > FIELD_MAXS[3])
+ return false;
+ if (min < FIELD_MINS[4] || min > FIELD_MAXS[4])
+ return false;
+ if (sec < FIELD_MINS[5] || sec > FIELD_MAXS[5])
+ return false;
+ if (millis < FIELD_MINS[6] || millis > FIELD_MAXS[6])
+ return false;
+
+ // Check whether leap month.
+ if (month == 2)
+ if (isLeapYear(year)) {
+ if (month > DAYS_OF_MONTH_LEAP[1])
+ return false;
+ } else {
+ if (month > DAYS_OF_MONTH_ORDI[1])
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Check whether the given time zone value is a valid time zone following the gregorian calendar system.
+ * <p/>
+ * The valid timezone is within the range of:<br/>
+ * - Hours: UTC -12 (Y, or Yankee Time Zone) to UTC +14 (LINT, or Line Islands Time) <br/>
+ * - Minutes: currently the available minutes include 00, 30 and 45.
+ * <p/>
+ * Reference: http://www.timeanddate.com/library/abbreviations/timezones/
+ * <p/>
+ *
+ * @param timezone
+ * @return
+ */
+ public boolean validateTimeZone(int timezone) {
+ short tzMin = (short) ((timezone % 4) * 15);
+
+ if (tzMin < -60 || tzMin >= 60) {
+ return false;
+ }
+
+ short tzHr = (short) (timezone / 4);
+
+ if (tzHr < -12 && tzHr > 14) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Validate the given chronon time and time zone.
+ *
+ * @param year
+ * @param month
+ * @param day
+ * @param hour
+ * @param min
+ * @param sec
+ * @param millis
+ * @param timezone
+ * @return
+ */
+ public boolean validate(int year, int month, int day, int hour, int min, int sec, int millis, int timezone) {
+ return validate(year, month, day, hour, min, sec, millis) && validateTimeZone(timezone);
+ }
+
+ /**
+ * Get the UTC chronon time of the given date time and time zone.
+ *
+ * @param year
+ * @param month
+ * @param day
+ * @param hour
+ * @param min
+ * @param sec
+ * @param millis
+ * @param timezone
+ * @return
+ */
+ public long getChronon(int year, int month, int day, int hour, int min, int sec, int millis, int timezone) {
+ // Added milliseconds for all fields but month and day
+ long chrononTime = chrononizeBeginningOfYear(year) + (hour - timezone / 4) * CHRONON_OF_HOUR
+ + (min - (timezone % 4) * 15) * CHRONON_OF_MINUTE + sec * CHRONON_OF_SECOND + millis;
+
+ // Added milliseconds for days of the month.
+ chrononTime += (day - 1 + DAYS_SINCE_MONTH_BEGIN_ORDI[month - 1]) * CHRONON_OF_DAY;
+
+ // Adjust the leap year
+ if (month > 2 && isLeapYear(year)) {
+ chrononTime += CHRONON_OF_DAY;
+ }
+
+ return chrononTime;
+ }
+
+ /**
+ * Get the chronon time (number of milliseconds) of the given time and time zone.
+ *
+ * @param hour
+ * @param min
+ * @param sec
+ * @param millis
+ * @param timezone
+ * @return
+ */
+ public int getChronon(int hour, int min, int sec, int millis, int timezone) {
+ // Added milliseconds for all fields but month and day
+ int chrononTime = (hour - timezone / 4) * CHRONON_OF_HOUR + (min - (timezone % 4) * 15) * CHRONON_OF_MINUTE
+ + sec * CHRONON_OF_SECOND + millis;
+ return chrononTime;
+ }
+
+ /**
+ * Get the extended string representation of the given UTC chronon time under the given time zone. Only fields before
+ * the given field index will be returned.
+ * <p/>
+ * The extended string representation is like:<br/>
+ * [-]YYYY-MM-DDThh:mm:ss.xxx[Z|[+|-]hh:mm]
+ *
+ * @param chrononTime
+ * @param timezone
+ * @param sbder
+ * @param untilField
+ */
+ public void getExtendStringRepWithTimezoneUntilField(long chrononTime, int timezone, StringBuilder sbder,
+ Fields startField, Fields untilField) {
+
+ int year = getYear(chrononTime);
+ int month = getMonthOfYear(chrononTime, year);
+
+ switch (startField) {
+ case YEAR:
+ sbder.append(String.format(year < 0 ? "%05d" : "%04d", year));
+ if (untilField == Fields.YEAR) {
+ return;
+ }
+ case MONTH:
+ if (startField != Fields.MONTH)
+ sbder.append("-");
+ sbder.append(String.format("%02d", month));
+ if (untilField == Fields.MONTH) {
+ return;
+ }
+ case DAY:
+ if (startField != Fields.DAY)
+ sbder.append("-");
+ sbder.append(String.format("%02d", getDayOfMonthYear(chrononTime, year, month)));
+ if (untilField == Fields.DAY) {
+ break;
+ }
+ case HOUR:
+ if (startField != Fields.HOUR)
+ sbder.append("T");
+ sbder.append(String.format("%02d", getHourOfDay(chrononTime)));
+ if (untilField == Fields.HOUR) {
+ break;
+ }
+ case MINUTE:
+ if (startField != Fields.MINUTE)
+ sbder.append(":");
+ sbder.append(String.format("%02d", getMinOfHour(chrononTime)));
+ if (untilField == Fields.MINUTE) {
+ break;
+ }
+ case SECOND:
+ if (startField != Fields.SECOND)
+ sbder.append(":");
+ sbder.append(String.format("%02d", getSecOfMin(chrononTime)));
+ // add millisecond as the precision fields of a second
+ sbder.append(".").append(String.format("%03d", getMillisOfSec(chrononTime)));
+ break;
+ }
+
+ if (untilField.compareTo(Fields.DAY) > 0) {
+ sbder.append("Z");
+ } else {
+ short tzMin = (short) ((timezone % 4) * 15);
+ short tzHr = (short) (timezone / 4);
+ sbder.append((tzHr >= 0 ? "+" : "-")).append(String.format("%02d", (tzHr < 0 ? -tzHr : tzHr))).append(":")
+ .append(String.format("%02d", tzMin));
+ }
+ }
+
+ /**
+ * Get the basic string representation of a chronon time with the given time zone.
+ *
+ * @param chrononTime
+ * @param timezone
+ * @param sbder
+ */
+ public void getBasicStringRepWithTimezoneUntilField(long chrononTime, int timezone, StringBuilder sbder,
+ Fields startField, Fields untilField) {
+ int year = getYear(chrononTime);
+ int month = getMonthOfYear(chrononTime, year);
+
+ switch (startField) {
+ case YEAR:
+ sbder.append(String.format(year < 0 ? "%05d" : "%04d", year));
+ if (untilField == Fields.YEAR) {
+ return;
+ }
+ case MONTH:
+ sbder.append(String.format("%02d", month));
+ if (untilField == Fields.MONTH) {
+ return;
+ }
+ case DAY:
+ sbder.append(String.format("%02d", getDayOfMonthYear(chrononTime, year, month)));
+ if (untilField == Fields.DAY) {
+ break;
+ }
+ case HOUR:
+ sbder.append(String.format("%02d", getHourOfDay(chrononTime)));
+ if (untilField == Fields.HOUR) {
+ break;
+ }
+ case MINUTE:
+ sbder.append(String.format("%02d", getMinOfHour(chrononTime)));
+ if (untilField == Fields.MINUTE) {
+ break;
+ }
+ case SECOND:
+ sbder.append(String.format("%02d", getSecOfMin(chrononTime)));
+ // add millisecond as the precision fields of a second
+ sbder.append(String.format("%03d", getMillisOfSec(chrononTime)));
+ break;
+ }
+
+ if (untilField.compareTo(Fields.DAY) > 0) {
+ sbder.append("Z");
+ } else {
+ short tzMin = (short) ((timezone % 4) * 15);
+ short tzHr = (short) (timezone / 4);
+ sbder.append((tzHr >= 0 ? "+" : "-")).append(String.format("%02d", (tzHr < 0 ? -tzHr : tzHr)))
+ .append(String.format("%02d", tzMin));
+ }
+ }
+
+ /**
+ * Get the extended string representation of the given months and milliseconds (duration) time. *
+ * <p/>
+ * The extended and simple string representation is like:<br/>
+ * [-]PnYnMnDTnHnMnS
+ *
+ * @param milliseconds
+ * @param months
+ * @param sbder
+ */
+
+ public void getDurationExtendStringRepWithTimezoneUntilField(long milliseconds, int months, StringBuilder sbder) {
+
+ boolean positive = true;
+
+ // set the negative flag. "||" is necessary in case that months field is not there (so it is 0)
+ if (months < 0 || milliseconds < 0) {
+ months *= -1;
+ milliseconds *= -1;
+ positive = false;
+ }
+
+ int month = getDurationMonth(months);
+ int year = getDurationYear(months);
+ int millisecond = getDurationMillisecond(milliseconds);
+ int second = getDurationSecond(milliseconds);
+ int minute = getDurationMinute(milliseconds);
+ int hour = getDurationHour(milliseconds);
+ int day = getDurationDay(milliseconds);
+
+ if (!positive) {
+ sbder.append("-");
+ }
+ sbder.append("P");
+ sbder.append((year != 0) ? year + "Y" : "");
+ sbder.append((month != 0) ? month + "M" : "");
+ sbder.append((day != 0) ? day + "D" : "");
+ sbder.append((hour != 0 || minute != 0 || second != 0 || millisecond != 0) ? "T" : "");
+ sbder.append((hour != 0) ? hour + "H" : "");
+ sbder.append((minute != 0) ? minute + "M" : "");
+ sbder.append((second != 0 || millisecond != 0) ? second : "");
+ if (millisecond > 0)
+ sbder.append("." + millisecond);
+ sbder.append((second != 0 || millisecond != 0) ? "S" : "");
+ }
+
+ /**
+ * Check whether a given year is a leap year.
+ *
+ * @param year
+ * @return
+ */
+ protected boolean isLeapYear(int year) {
+ return ((year & 3) == 0) && ((year % 100) != 0 || (year % 400) == 0);
+ }
+
+ /**
+ * From Joda library GregorianChronology class: The basic calculation is
+ * (y / 4) - (y / 100) + (y / 400). <br/>
+ * Use y >> 2 ( (y + 3) >> 2 for negative y value) to replace y / 4 reveals eliminates two divisions.
+ *
+ * @param year
+ * @return
+ */
+ private long chrononizeBeginningOfYear(int year) {
+ int leapYears = year / 100;
+ if (year < 0) {
+ // From Joda library GregorianChronology class
+ // The basic calculation is (y / 4) - (y / 100) + (y / 400)
+ // Use (y + 3) >> 2 to replace y / 4 reveals eliminates two divisions.
+ leapYears = ((year + 3) >> 2) - leapYears + ((leapYears + 3) >> 2) - 1;
+ } else {
+ leapYears = (year >> 2) - leapYears + (leapYears >> 2);
+ if (isLeapYear(year)) {
+ leapYears--;
+ }
+ }
+ return (year * 365L + (leapYears - DAYS_0000_TO_1970)) * CHRONON_OF_DAY;
+ }
+
+ /**
+ * Get the year for the given chronon time.
+ * <p/>
+ * This code is directly from the Joda library BadicChronology.java.<br/>
+ * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May 7th, 2012.
+ *
+ * @param chrononTime
+ * @return
+ */
+ public int getYear(long chrononTime) {
+ // Get an initial estimate of the year, and the millis value that
+ // represents the start of that year. Then verify estimate and fix if
+ // necessary.
+
+ // Initial estimate uses values divided by two to avoid overflow.
+ long unitMillis = CHRONON_OF_YEAR / 2;
+ long i2 = (chrononTime >> 1) + (1970L * CHRONON_OF_YEAR) / 2;
+ if (i2 < 0) {
+ i2 = i2 - unitMillis + 1;
+ }
+ int year = (int) (i2 / unitMillis);
+
+ long yearStart = chrononizeBeginningOfYear(year);
+ long diff = chrononTime - yearStart;
+
+ if (diff < 0) {
+ year--;
+ } else if (diff >= CHRONON_OF_DAY * 365L) {
+ // One year may need to be added to fix estimate.
+ long oneYear;
+ if (isLeapYear(year)) {
+ oneYear = CHRONON_OF_DAY * 366L;
+ } else {
+ oneYear = CHRONON_OF_DAY * 365L;
+ }
+
+ yearStart += oneYear;
+
+ if (yearStart <= chrononTime) {
+ // Didn't go too far, so actually add one year.
+ year++;
+ }
+ }
+
+ return year;
+ }
+
+ /**
+ * Get the month of the year for the given chronon time and the year.
+ * <p/>
+ * This code is directly from the Joda library BasicGJChronology.java.<br/>
+ * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May 7th, 2012.
+ * <p/>
+ *
+ * @param millis
+ * @param year
+ * @return
+ */
+ public int getMonthOfYear(long millis, int year) {
+ // Perform a binary search to get the month. To make it go even faster,
+ // compare using ints instead of longs. The number of milliseconds per
+ // year exceeds the limit of a 32-bit int's capacity, so divide by
+ // 1024. No precision is lost (except time of day) since the number of
+ // milliseconds per day contains 1024 as a factor. After the division,
+ // the instant isn't measured in milliseconds, but in units of
+ // (128/125)seconds.
+
+ int i = (int) ((millis - chrononizeBeginningOfYear(year)) >> 10);
+
+ // There are 86400000 milliseconds per day, but divided by 1024 is
+ // 84375. There are 84375 (128/125)seconds per day.
+
+ // if (isleap_year==true)
+ // if (i < 182 * 84375 /*Days before the end of June*/)
+ // if (i < 91 * 84375 /*Days before the end of March*/)
+ // if (i < 31 * 84375 /*Days before the end of January*/)
+ // Month is 1
+ // else if (i < 60 * 84375 /*Days before the end of February of leap year*/)
+ // Month is 2
+ // else
+ // Month is 3
+ // else
+ // if (i < 121 * 84375 /*Days before the end of April*/)
+ // Month is 4
+ // else if (i < 152 * 84375 /*Days before the end of May*/)
+ // Month is 5
+ // else
+ // Month is 6
+ // else
+ // if (i < 274 * 84375 /*Days before the end of September*/)
+ // if (i < 213 * 84375 /*Days before the end of July*/)
+ // Month is 7
+ // else if (i < 244 * 84375 /*Days before the end of August*/)
+ // Month is 8
+ // else
+ // Month is 9
+ // else
+ // if (i < 305 * 84375 /*Days before the end of October*/)
+ // Month is 10
+ // else if (i < 335 * 84375 /*Days before the end of November*/)
+ // Month is 11
+ // else
+ // Month is 12
+ // else /*Not a leap year*/
+ // if (i < 181 * 84375 /*Days before the end of June*/)
+ // if (i < 90 * 84375 /*Days before the end of March*/)
+ // if (i < 31 * 84375 /*Days before the end of January*/)
+ // Month is 1
+ // else if (i < 59 * 84375 /*Days before the end of February of NON leap year*/)
+ // Month is 2
+ // else
+ // Month is 3
+ // else
+ // if (i < 120 * 84375 /*Days before the end of April*/)
+ // Month is 4
+ // else if (i < 151 * 84375 /*Days before the end of May*/)
+ // Month is 5
+ // else
+ // Month is 6
+ // else
+ // if (i < 273 * 84375 /*Days before the end of September*/)
+ // if (i < 213 * 84375 /*Days before the end of July*/)
+ // Month is 7
+ // else if (i < 243 * 84375 /*Days before the end of August*/)
+ // Month is 8
+ // else
+ // Month is 9
+ // else
+ // if (i < 304 * 84375 /*Days before the end of October*/)
+ // Month is 10
+ // else if (i < 334 * 84375 /*Days before the end of November*/)
+ // Month is 11
+ // else
+ // Month is 12
+
+ return (isLeapYear(year)) ? ((i < 182 * 84375) ? ((i < 91 * 84375) ? ((i < 31 * 84375) ? 1
+ : (i < 60 * 84375) ? 2 : 3) : ((i < 121 * 84375) ? 4 : (i < 152 * 84375) ? 5 : 6))
+ : ((i < 274 * 84375) ? ((i < 213 * 84375) ? 7 : (i < 244 * 84375) ? 8 : 9) : ((i < 305 * 84375) ? 10
+ : (i < 335 * 84375) ? 11 : 12)))
+ : ((i < 181 * 84375) ? ((i < 90 * 84375) ? ((i < 31 * 84375) ? 1 : (i < 59 * 84375) ? 2 : 3)
+ : ((i < 120 * 84375) ? 4 : (i < 151 * 84375) ? 5 : 6))
+ : ((i < 273 * 84375) ? ((i < 212 * 84375) ? 7 : (i < 243 * 84375) ? 8 : 9)
+ : ((i < 304 * 84375) ? 10 : (i < 334 * 84375) ? 11 : 12)));
+ }
+
+ /**
+ * Get the day of the given month and year for the input chronon time.
+ * <p/>
+ * This function is directly from Joda Library BasicChronology.java.<br/>
+ * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May 7th, 2012.
+ * <p/>
+ *
+ * @param millis
+ * @param year
+ * @param month
+ * @return
+ */
+ public int getDayOfMonthYear(long millis, int year, int month) {
+ long dateMillis = chrononizeBeginningOfYear(year);
+ dateMillis += DAYS_SINCE_MONTH_BEGIN_ORDI[month - 1] * CHRONON_OF_DAY;
+ if (isLeapYear(year) && month > 2) {
+ dateMillis += CHRONON_OF_DAY;
+ }
+ return (int) ((millis - dateMillis) / CHRONON_OF_DAY) + 1;
+ }
+
+ /**
+ * Get the hour of the day for the given chronon time.
+ *
+ * @param millis
+ * @return
+ */
+ public int getHourOfDay(long millis) {
+ int hour = (int) ((millis % CHRONON_OF_DAY) / CHRONON_OF_HOUR);
+
+ if (millis < 0) {
+ if (millis % CHRONON_OF_HOUR == 0) {
+ if (hour < 0) {
+ hour += 24;
+ }
+ } else {
+ hour += 23;
+ }
+ }
+
+ return hour;
+ }
+
+ /**
+ * Get the minute of the hour for the given chronon time.
+ *
+ * @param millis
+ * @return
+ */
+ public int getMinOfHour(long millis) {
+ int min = (int) ((millis % CHRONON_OF_HOUR) / CHRONON_OF_MINUTE);
+ if (millis < 0) {
+ if (millis % CHRONON_OF_MINUTE == 0) {
+ if (min < 0) {
+ min += 60;
+ }
+ } else {
+ min += 59;
+ }
+ }
+ return min;
+ }
+
+ /**
+ * Get the second of the minute for the given chronon time.
+ *
+ * @param millis
+ * @return
+ */
+ public int getSecOfMin(long millis) {
+ int sec = (int) ((millis % CHRONON_OF_MINUTE) / CHRONON_OF_SECOND);
+ if (millis < 0) {
+ if (millis % CHRONON_OF_SECOND == 0) {
+ if (sec < 0) {
+ sec += 60;
+ }
+ } else {
+ sec += 59;
+ }
+ }
+ return sec;
+ }
+
+ /**
+ * Get the millisecond of the second for the given chronon time.
+ *
+ * @param millis
+ * @return
+ */
+ public int getMillisOfSec(long millis) {
+ int ms = (int) (millis % CHRONON_OF_SECOND);
+ if (millis < 0 && ms < 0) {
+ ms += 1000;
+ }
+ return ms;
+ }
+
+ public int getDurationMonth(int months) {
+ return (months % 12);
+ }
+
+ public int getDurationYear(int months) {
+ return (months / 12);
+ }
+
+ public int getDurationMillisecond(long milliseconds) {
+ return (int) (milliseconds % 1000);
+ }
+
+ public int getDurationSecond(long milliseconds) {
+ return (int) ((milliseconds % 60000) / 1000);
+ }
+
+ public int getDurationMinute(long milliseconds) {
+ return (int) ((milliseconds % 3600000) / 60000);
+ }
+
+ public int getDurationHour(long milliseconds) {
+ return (int) ((milliseconds % (86400000)) / 3600000);
+ }
+
+ public int getDurationDay(long milliseconds) {
+ return (int) (milliseconds / (86400000));
+ }
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ICalendarSystem.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ICalendarSystem.java
new file mode 100644
index 0000000..be9545d
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ICalendarSystem.java
@@ -0,0 +1,47 @@
+package edu.uci.ics.asterix.om.base.temporal;
+
+public interface ICalendarSystem {
+
+ /**
+ * check whether the given time stamp is valid in the calendar system.
+ *
+ * @param year
+ * @param month
+ * @param day
+ * @param hour
+ * @param min
+ * @param sec
+ * @param millis
+ * @param timezone
+ * @return
+ */
+ public boolean validate(int year, int month, int day, int hour, int min, int sec, int millis, int timezone);
+
+ /**
+ * get the chronon time for the given time stamp in the calendar system.
+ *
+ * @param year
+ * @param month
+ * @param day
+ * @param hour
+ * @param min
+ * @param sec
+ * @param millis
+ * @param timezone
+ * @return
+ */
+ public long getChronon(int year, int month, int day, int hour, int min, int sec, int millis, int timezone);
+
+ /**
+ * get the chronon time for the given time in the calendar system
+ *
+ * @param hour
+ * @param min
+ * @param sec
+ * @param millis
+ * @param timezone
+ * @return
+ */
+ public int getChronon(int hour, int min, int sec, int millis, int timezone);
+
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ICharSequenceAccessor.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ICharSequenceAccessor.java
new file mode 100644
index 0000000..a04c04f
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ICharSequenceAccessor.java
@@ -0,0 +1,9 @@
+package edu.uci.ics.asterix.om.base.temporal;
+
+public interface ICharSequenceAccessor<T> {
+
+ public char getCharAt(int index);
+
+ public int getLength();
+
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/StringCharSequenceAccessor.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/StringCharSequenceAccessor.java
new file mode 100644
index 0000000..6439db8
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/StringCharSequenceAccessor.java
@@ -0,0 +1,23 @@
+package edu.uci.ics.asterix.om.base.temporal;
+
+public class StringCharSequenceAccessor implements ICharSequenceAccessor<String> {
+
+ private String string;
+ private int offset;
+
+ @Override
+ public char getCharAt(int index) {
+ return string.charAt(index + offset);
+ }
+
+ public void reset(String obj, int offset) {
+ string = obj;
+ this.offset = offset;
+ }
+
+ @Override
+ public int getLength() {
+ return string.length() - offset;
+ }
+
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/NonTaggedFormatUtil.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/NonTaggedFormatUtil.java
index e1eaa7c..712843a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/NonTaggedFormatUtil.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/NonTaggedFormatUtil.java
@@ -90,8 +90,9 @@
case INT64:
case DOUBLE:
case DATETIME:
- case DURATION:
return 8;
+ case DURATION:
+ return 12;
case POINT:
return 16;
case POINT3D:
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
index 25b2f84..5ae1465 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
@@ -8,6 +8,9 @@
import edu.uci.ics.asterix.om.base.ADate;
import edu.uci.ics.asterix.om.base.AMutableDate;
import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.base.temporal.ByteArrayCharSequenceAccessor;
+import edu.uci.ics.asterix.om.base.temporal.ADateAndTimeParser;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
import edu.uci.ics.asterix.om.types.ATypeTag;
@@ -28,6 +31,9 @@
public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "date", 1);
private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+ private final static ByteArrayCharSequenceAccessor charAccessor = new ByteArrayCharSequenceAccessor();
+
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
public IFunctionDescriptor createFunctionDescriptor() {
return new ADateConstructorDescriptor();
@@ -47,12 +53,8 @@
private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
private ICopyEvaluator eval = args[0].createEvaluator(outInput);
- private int offset;
- private short year, month, day, hour, minute, value;
- private byte timezonePart = 0;
- private boolean positive = true;
private String errorMessage = "This can not be an instance of date";
- private AMutableDate aDate = new AMutableDate(0, 0, 0, 0);
+ private AMutableDate aDate = new AMutableDate(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADate> dateSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.ADATE);
@@ -68,73 +70,29 @@
eval.evaluate(tuple);
byte[] serString = outInput.getByteArray();
if (serString[0] == SER_STRING_TYPE_TAG) {
- offset = 3;
- if (serString[offset] == '-') {
- offset++;
- positive = false;
- }
+ charAccessor.reset(serString, 3, 0);
+ long chrononTimeInMs = ADateAndTimeParser.parseDatePart(charAccessor, true);
- if (serString[offset + 4] != '-' || serString[offset + 7] != '-')
- throw new AlgebricksException(errorMessage);
+ short temp = 0;
+ if (chrononTimeInMs < 0
+ && chrononTimeInMs % GregorianCalendarSystem.CHRONON_OF_DAY != 0)
+ temp = 1;
- year = getValue(serString, offset, 4);
- month = getValue(serString, offset + 5, 2);
- day = getValue(serString, offset + 8, 2);
+ aDate.setValue((int) (chrononTimeInMs / GregorianCalendarSystem.CHRONON_OF_DAY) - temp);
- if (year < 0 || year > 9999 || month < 0 || month > 12 || day < 0 || day > 31)
- throw new AlgebricksException(errorMessage);
-
- offset += 10;
-
- if (outInput.getLength() > offset) {
- if (serString[offset] == 'Z')
- timezonePart = 0;
- else {
- if ((serString[offset] != '+' && serString[offset] != '-')
- || (serString[offset + 3] != ':'))
- throw new AlgebricksException(errorMessage);
-
- hour = getValue(serString, offset + 1, 2);
- minute = getValue(serString, offset + 4, 2);
-
- if (hour < 0 || hour > 24 || (hour == 24 && minute != 0)
- || (minute != 0 && minute != 15 && minute != 30 && minute != 45))
- throw new AlgebricksException(errorMessage);
-
- if (serString[offset] == '-')
- timezonePart = (byte) -((hour * 4) + minute / 15);
- else
- timezonePart = (byte) ((hour * 4) + minute / 15);
- }
-
- }
-
- if (!positive)
- year *= -1;
-
- aDate.setValue(year, month, day, timezonePart);
dateSerde.serialize(aDate, out);
} else if (serString[0] == SER_NULL_TYPE_TAG)
nullSerde.serialize(ANull.NULL, out);
else
throw new AlgebricksException(errorMessage);
+
} catch (IOException e1) {
throw new AlgebricksException(errorMessage);
+ } catch (Exception e2) {
+ throw new AlgebricksException(e2.getMessage());
}
}
-
- private short getValue(byte[] b, int offset, int numberOfDigits) throws AlgebricksException {
- value = 0;
- for (int i = 0; i < numberOfDigits; i++) {
- if ((b[offset] >= '0' && b[offset] <= '9'))
- value = (short) (value * 10 + b[offset++] - '0');
- else
- throw new AlgebricksException(errorMessage);
-
- }
- return value;
- }
};
}
};
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
index c37d646..2e1d0ca 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
@@ -8,6 +8,8 @@
import edu.uci.ics.asterix.om.base.ADateTime;
import edu.uci.ics.asterix.om.base.AMutableDateTime;
import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.base.temporal.ByteArrayCharSequenceAccessor;
+import edu.uci.ics.asterix.om.base.temporal.ADateAndTimeParser;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
import edu.uci.ics.asterix.om.types.ATypeTag;
@@ -28,6 +30,9 @@
public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "datetime", 1);
private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+ private final static ByteArrayCharSequenceAccessor charAccessor = new ByteArrayCharSequenceAccessor();
+
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
public IFunctionDescriptor createFunctionDescriptor() {
return new ADateTimeConstructorDescriptor();
@@ -47,12 +52,8 @@
private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
private ICopyEvaluator eval = args[0].createEvaluator(outInput);
- private int offset;
- private short hour, minute, second, msecond, year, month, day, timezoneHour, timezoneMinute, value;
- private byte timezonePart = 0;
- private boolean positive = true;
private String errorMessage = "This can not be an instance of datetime";
- private AMutableDateTime aDateTime = new AMutableDateTime(0, 0, 0, 0, 0, 0, 0, 0, 0);
+ private AMutableDateTime aDateTime = new AMutableDateTime(0L);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADateTime> datetimeSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.ADATETIME);
@@ -68,79 +69,26 @@
eval.evaluate(tuple);
byte[] serString = outInput.getByteArray();
if (serString[0] == SER_STRING_TYPE_TAG) {
+ charAccessor.reset(serString, 3, 0);
- offset = 3;
- if (serString[offset] == '-') {
- offset++;
- positive = false;
- }
+ // +1 if it is negative (-)
+ short timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
- if (serString[offset + 4] != '-' || serString[offset + 7] != '-')
- throw new AlgebricksException(errorMessage);
+ if (charAccessor.getCharAt(timeOffset + 10) != 'T'
+ && charAccessor.getCharAt(timeOffset + 8) != 'T')
+ throw new AlgebricksException(errorMessage + ": missing T");
- year = getValue(serString, offset, 4);
- month = getValue(serString, offset + 5, 2);
- day = getValue(serString, offset + 8, 2);
+ // if extended form 11, else 9
+ timeOffset += (charAccessor.getCharAt(timeOffset + 13) == ':') ? (short) (11)
+ : (short) (9);
- if (year < 0 || year > 9999 || month < 0 || month > 12 || day < 0 || day > 31)
- throw new AlgebricksException(errorMessage);
+ long chrononTimeInMs = ADateAndTimeParser.parseDatePart(charAccessor, false);
- if (!positive)
- year *= -1;
+ charAccessor.reset(serString, 3, timeOffset);
- if (serString[offset + 10] != 'T')
- throw new AlgebricksException(errorMessage);
+ chrononTimeInMs += ADateAndTimeParser.parseTimePart(charAccessor);
- offset += 11;
-
- if (serString[offset + 2] != ':' || serString[offset + 5] != ':')
- throw new AlgebricksException(errorMessage);
-
- hour = getValue(serString, offset, 2);
- minute = getValue(serString, offset + 3, 2);
- second = getValue(serString, offset + 6, 2);
-
- msecond = 0;
- if (serString[offset + 8] == ':') {
- msecond = getValue(serString, offset + 9, 3);
- if (hour < 0 || hour > 24 || minute < 0 || minute > 59 || second < 0 || second > 59
- || msecond < 0 || msecond > 999
- || (hour == 24 && (minute != 0 || second != 0 || msecond != 0)))
- throw new AlgebricksException(errorMessage);
- offset += 12;
- } else {
- if (hour < 0 || hour > 24 || minute < 0 || minute > 59 || second < 0 || second > 59
- || (hour == 24 && (minute != 0 || second != 0)))
- throw new AlgebricksException(errorMessage);
- offset += 8;
- }
-
- if (outInput.getLength() > offset) {
- if (serString[offset] == 'Z')
- timezonePart = 0;
- else {
- if ((serString[offset] != '+' && serString[offset] != '-')
- || (serString[offset + 3] != ':'))
- throw new AlgebricksException(errorMessage);
-
- timezoneHour = getValue(serString, offset + 1, 2);
- timezoneMinute = getValue(serString, offset + 4, 2);
-
- if (timezoneHour < 0
- || timezoneHour > 24
- || (timezoneHour == 24 && timezoneMinute != 0)
- || (timezoneMinute != 0 && timezoneMinute != 15 && timezoneMinute != 30 && timezoneMinute != 45))
- throw new AlgebricksException(errorMessage);
-
- if (serString[offset] == '-')
- timezonePart = (byte) -((timezoneHour * 4) + timezoneMinute / 15);
- else
- timezonePart = (byte) ((timezoneHour * 4) + timezoneMinute / 15);
- }
-
- }
-
- aDateTime.setValue(year, month, day, hour, minute, second, msecond, 0, timezonePart);
+ aDateTime.setValue(chrononTimeInMs);
datetimeSerde.serialize(aDateTime, out);
} else if (serString[0] == SER_NULL_TYPE_TAG)
nullSerde.serialize(ANull.NULL, out);
@@ -148,20 +96,10 @@
throw new AlgebricksException(errorMessage);
} catch (IOException e1) {
throw new AlgebricksException(errorMessage);
+ } catch (Exception e) {
+ throw new AlgebricksException(e.getMessage());
}
}
-
- private short getValue(byte[] b, int offset, int numberOfDigits) throws AlgebricksException {
- value = 0;
- for (int i = 0; i < numberOfDigits; i++) {
- if ((b[offset] >= '0' && b[offset] <= '9'))
- value = (short) (value * 10 + b[offset++] - '0');
- else
- throw new AlgebricksException(errorMessage);
-
- }
- return value;
- }
};
}
};
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
index c2215ff..24934b1 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
@@ -1,13 +1,14 @@
package edu.uci.ics.asterix.runtime.evaluators.constructors;
import java.io.DataOutput;
-import java.io.IOException;
import edu.uci.ics.asterix.common.functions.FunctionConstants;
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
import edu.uci.ics.asterix.om.base.ADuration;
import edu.uci.ics.asterix.om.base.AMutableDuration;
import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.base.temporal.ADurationParser;
+import edu.uci.ics.asterix.om.base.temporal.ByteArrayCharSequenceAccessor;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
import edu.uci.ics.asterix.om.types.ATypeTag;
@@ -28,6 +29,9 @@
public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "duration", 1);
private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+ private final static ByteArrayCharSequenceAccessor charAccessor = new ByteArrayCharSequenceAccessor();
+
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
public IFunctionDescriptor createFunctionDescriptor() {
return new ADurationConstructorDescriptor();
@@ -47,10 +51,6 @@
private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
private ICopyEvaluator eval = args[0].createEvaluator(outInput);
- private int offset;
- private int value = 0, hour = 0, minute = 0, second = 0, year = 0, month = 0, day = 0;
- private boolean isYear = true, isMonth = true, isDay = true, isHour = true, isMinute = true,
- isSecond = true, isTime = false, timeItem = true, positive = true;
private String errorMessage = "This can not be an instance of duration";
private AMutableDuration aDuration = new AMutableDuration(0, 0);
@SuppressWarnings("unchecked")
@@ -67,120 +67,21 @@
outInput.reset();
eval.evaluate(tuple);
byte[] serString = outInput.getByteArray();
+
if (serString[0] == SER_STRING_TYPE_TAG) {
- offset = 3;
- if (serString[offset] == '-') {
- offset++;
- positive = false;
- }
- if (serString[offset++] != 'D')
- throw new AlgebricksException(errorMessage);
- for (; offset < outInput.getLength(); offset++) {
- if (serString[offset] >= '0' && serString[offset] <= '9')
- value = value * 10 + serString[offset] - '0';
- else {
- switch (serString[offset]) {
- case 'Y':
- if (isYear) {
- year = value;
- isYear = false;
- } else
- throw new AlgebricksException(errorMessage);
- break;
- case 'M':
- if (!isTime) {
- if (isMonth) {
- if (value < 0 || value > 11)
- throw new AlgebricksException(errorMessage);
- else {
- month = value;
- isMonth = false;
- }
- } else
- throw new AlgebricksException(errorMessage);
- } else if (isMinute) {
- if (value < 0 || value > 59)
- throw new AlgebricksException(errorMessage);
- else {
- minute = value;
- isMinute = false;
- timeItem = false;
- }
- } else
- throw new AlgebricksException(errorMessage);
- break;
- case 'D':
- if (isDay) {
- if (value < 0 || value > 30)
- throw new AlgebricksException(errorMessage);
- else {
- day = value;
- isDay = false;
- }
- } else
- throw new AlgebricksException(errorMessage);
- break;
- case 'T':
- if (!isTime) {
- isTime = true;
- timeItem = true;
- } else
- throw new AlgebricksException(errorMessage);
- break;
+ charAccessor.reset(serString, 3, 0);
- case 'H':
- if (isHour) {
- if (value < 0 || value > 23)
- throw new AlgebricksException(errorMessage);
- else {
- hour = value;
- isHour = false;
- timeItem = false;
- }
- } else
- throw new AlgebricksException(errorMessage);
- break;
- case 'S':
- if (isSecond) {
- if (value < 0 || value > 59)
- throw new AlgebricksException(errorMessage);
- else {
- second = value;
- isSecond = false;
- timeItem = false;
- }
- } else
- throw new AlgebricksException(errorMessage);
- break;
- default:
- throw new AlgebricksException(errorMessage);
+ ADurationParser.parse(charAccessor, aDuration);
- }
- value = 0;
- }
- }
-
- if (isTime && timeItem)
- throw new AlgebricksException(errorMessage);
-
- if (isYear && isMonth && isDay && !isTime)
- throw new AlgebricksException(errorMessage);
-
- if (positive)
- aDuration.setValue(year * 12 + month, day * 24 * 3600 + 3600 * hour + 60 * minute
- + second);
- else
- aDuration.setValue(-1 * (year * 12 + month), -1
- * (day * 24 * 3600 + 3600 * hour + 60 * minute + second));
durationSerde.serialize(aDuration, out);
} else if (serString[0] == SER_NULL_TYPE_TAG)
nullSerde.serialize(ANull.NULL, out);
else
throw new AlgebricksException(errorMessage);
- } catch (IOException e1) {
- throw new AlgebricksException(errorMessage);
+ } catch (Exception e) {
+ throw new AlgebricksException(e.getMessage());
}
}
};
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java
index 8a7ac44..fc35bcd 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java
@@ -8,6 +8,8 @@
import edu.uci.ics.asterix.om.base.AMutableTime;
import edu.uci.ics.asterix.om.base.ANull;
import edu.uci.ics.asterix.om.base.ATime;
+import edu.uci.ics.asterix.om.base.temporal.ByteArrayCharSequenceAccessor;
+import edu.uci.ics.asterix.om.base.temporal.ADateAndTimeParser;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
import edu.uci.ics.asterix.om.types.ATypeTag;
@@ -28,6 +30,7 @@
public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "time", 1);
private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+ private final static ByteArrayCharSequenceAccessor charAccessor = new ByteArrayCharSequenceAccessor();
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
public IFunctionDescriptor createFunctionDescriptor() {
@@ -48,11 +51,8 @@
private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
private ICopyEvaluator eval = args[0].createEvaluator(outInput);
- private int offset;
- private short hour, minute, second, msecond, timezoneHour, timezoneMinute, value;
- private byte timezonePart = 0;
private String errorMessage = "This can not be an instance of time";
- private AMutableTime aTime = new AMutableTime(0, 0, 0, 0, 0, 0);
+ private AMutableTime aTime = new AMutableTime(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ATime> timeSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.ATIME);
@@ -68,54 +68,10 @@
eval.evaluate(tuple);
byte[] serString = outInput.getByteArray();
if (serString[0] == SER_STRING_TYPE_TAG) {
- offset = 3;
- if (serString[offset + 2] != ':' || serString[offset + 5] != ':')
- throw new AlgebricksException(errorMessage);
+ charAccessor.reset(serString, 3, 0);
+ int chrononTimeInMs = ADateAndTimeParser.parseTimePart(charAccessor);
- hour = getValue(serString, offset, 2);
- minute = getValue(serString, offset + 3, 2);
- second = getValue(serString, offset + 6, 2);
- msecond = 0;
-
- if (serString[offset + 8] == ':') {
- msecond = getValue(serString, offset + 9, 3);
- if (hour < 0 || hour > 24 || minute < 0 || minute > 59 || second < 0 || second > 59
- || msecond < 0 || msecond > 999
- || (hour == 24 && (minute != 0 || second != 0 || msecond != 0)))
- throw new AlgebricksException(errorMessage);
- offset += 12;
- } else {
- if (hour < 0 || hour > 24 || minute < 0 || minute > 59 || second < 0 || second > 59
- || (hour == 24 && (minute != 0 || second != 0)))
- throw new AlgebricksException(errorMessage);
- offset += 8;
- }
-
- if (outInput.getLength() > offset) {
- if (serString[offset] == 'Z')
- timezonePart = 0;
- else {
- if ((serString[offset] != '+' && serString[offset] != '-')
- || (serString[offset + 3] != ':'))
- throw new AlgebricksException(errorMessage);
-
- timezoneHour = getValue(serString, offset + 1, 2);
- timezoneMinute = getValue(serString, offset + 4, 2);
-
- if (timezoneHour < 0
- || timezoneHour > 24
- || (timezoneHour == 24 && timezoneMinute != 0)
- || (timezoneMinute != 0 && timezoneMinute != 15 && timezoneMinute != 30 && timezoneMinute != 45))
- throw new AlgebricksException(errorMessage);
-
- if (serString[offset] == '-')
- timezonePart = (byte) -((timezoneHour * 4) + timezoneMinute / 15);
- else
- timezonePart = (byte) ((timezoneHour * 4) + timezoneMinute / 15);
- }
- }
-
- aTime.setValue(hour, minute, second, msecond, 0, timezonePart);
+ aTime.setValue(chrononTimeInMs);
timeSerde.serialize(aTime, out);
} else if (serString[0] == SER_NULL_TYPE_TAG)
@@ -124,19 +80,10 @@
throw new AlgebricksException(errorMessage);
} catch (IOException e1) {
throw new AlgebricksException(errorMessage);
+ } catch (Exception e) {
+ throw new AlgebricksException(e.getMessage());
}
}
-
- private short getValue(byte[] b, int offset, int numberOfDigits) throws AlgebricksException {
- value = 0;
- for (int i = 0; i < numberOfDigits; i++) {
- if ((b[offset] >= '0' && b[offset] <= '9'))
- value = (short) (value * 10 + b[offset++] - '0');
- else
- throw new AlgebricksException(errorMessage);
- }
- return value;
- }
};
}
};