Skip to content

Commit

Permalink
Issue #73. Work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
highsource committed May 4, 2015
1 parent dfd1b1b commit 9aa2596
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 19 deletions.
14 changes: 5 additions & 9 deletions nodejs/scripts/jsonix.js
Original file line number Diff line number Diff line change
Expand Up @@ -5130,8 +5130,7 @@ Jsonix.Schema.XSD.Calendar.GYEAR_PATTERN = "(" + Jsonix.Schema.XSD.Calendar.YEAR
Jsonix.Schema.XSD.Calendar.GMONTH_PATTERN = "(" + Jsonix.Schema.XSD.Calendar.SINGLE_MONTH_PATTERN + ")" + "(" + Jsonix.Schema.XSD.Calendar.TIMEZONE_PATTERN + ")?";
Jsonix.Schema.XSD.Calendar.GDAY_PATTERN = "(" + Jsonix.Schema.XSD.Calendar.SINGLE_DAY_PATTERN + ")" + "(" + Jsonix.Schema.XSD.Calendar.TIMEZONE_PATTERN + ")?";
Jsonix.Schema.XSD.Calendar.GYEAR_MONTH_PATTERN = "(" + Jsonix.Schema.XSD.Calendar.YEAR_PATTERN + ")" + "-" + "(" + Jsonix.Schema.XSD.Calendar.DAY_PATTERN + ")" + "(" + Jsonix.Schema.XSD.Calendar.TIMEZONE_PATTERN + ")?";

Jsonix.Schema.XSD.Calendar.GMONTH_DAY_SPLITTER = "(" + Jsonix.Schema.XSD.Calendar.SINGLE_MONTH_PATTERN + ")" +"-"+ "(" +Jsonix.Schema.XSD.Calendar.DAY_PATTERN +")" + "(" + Jsonix.Schema.XSD.Calendar.TIMEZONE_PATTERN + ")?";
Jsonix.Schema.XSD.Calendar.GMONTH_DAY_PATTERN = "(" + Jsonix.Schema.XSD.Calendar.SINGLE_MONTH_PATTERN + ")" +"-"+ "(" +Jsonix.Schema.XSD.Calendar.DAY_PATTERN +")" + "(" + Jsonix.Schema.XSD.Calendar.TIMEZONE_PATTERN + ")?";

Jsonix.Schema.XSD.Calendar.INSTANCE = new Jsonix.Schema.XSD.Calendar();
Jsonix.Schema.XSD.Calendar.INSTANCE.LIST = new Jsonix.Schema.XSD.List(Jsonix.Schema.XSD.Calendar.INSTANCE);
Expand Down Expand Up @@ -5541,11 +5540,10 @@ Jsonix.Schema.XSD.GYear = Jsonix.Class(Jsonix.Schema.XSD.Calendar, {
year : parseInt(results[1], 10),
timezone : this.convertTimeZoneString(results[5])
};

return splitedGYear;
} else {
throw new Error('Value [' + value + '] does not match the gYear pattern.');
}

throw new Error('Value [' + value + '] doesn\'t match the gYear pattern.');
}

});
Expand Down Expand Up @@ -5575,18 +5573,17 @@ Jsonix.Schema.XSD.GMonthDay = Jsonix.Class(Jsonix.Schema.XSD.Calendar, {
*/
splitGMonthDay : function(value) {

var gMonthDayExpression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.GMONTH_DAY_SPLITTER + "$");
var gMonthDayExpression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.GMONTH_DAY_PATTERN + "$");
var results = value.match(gMonthDayExpression);

if (results !== null) {
var splitedGMonthDay = {

month : parseInt(results[2], 10),
day : parseInt(results[3], 10),
timezone : this.convertTimeZoneString(results[5])
};

var shortMonths = [ 4, 6, 9, 11 ];
var shortMonths = [ 4, 6, 9, 11 ];
var validationFailed = false;

if (splitedGMonthDay.month === 2 && splitedGMonthDay.day > 29) {
Expand Down Expand Up @@ -5620,7 +5617,6 @@ Jsonix.Schema.XSD.GDay = Jsonix.Class(Jsonix.Schema.XSD.Calendar, {
returnValue.toString = function() {
return "EmptyXMLElement. Call embedded 'day' or 'timezone' property";
};

return returnValue;
},

Expand Down
5 changes: 5 additions & 0 deletions nodejs/scripts/tests/GH73/GH73Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ module.exports = {

test.equal(101, unmarshaller.unmarshalString('<GDateTypes year="0101"/>').value.year.year);
test.equal(-1234567, unmarshaller.unmarshalString('<GDateTypes year="-1234567"/>').value.year.year);
test.equal(1234567, unmarshaller.unmarshalString('<GDateTypes year="1234567"/>').value.year.year);
test.equal(2013, unmarshaller.unmarshalString('<GDateTypes year="2013-05:00"/>').value.year.year);
test.equal(-300, unmarshaller.unmarshalString('<GDateTypes year="2013-05:00"/>').value.year.timezone);
test.equal(-2013, unmarshaller.unmarshalString('<GDateTypes year="-2013+05:00"/>').value.year.year);
test.equal(300, unmarshaller.unmarshalString('<GDateTypes year="-2013+05:00"/>').value.year.timezone);
// TODO Exception
// test.equal(0, unmarshaller.unmarshalString('<GDateTypes year="0000"/>').value.year.year);

test.equal(1, unmarshaller.unmarshalString('<GDateTypes month="--01"/>').value.month.month);
test.equal(12, unmarshaller.unmarshalString('<GDateTypes month="--12-05:00"/>').value.month.month);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,7 @@ Jsonix.Schema.XSD.Calendar.GYEAR_PATTERN = "(" + Jsonix.Schema.XSD.Calendar.YEAR
Jsonix.Schema.XSD.Calendar.GMONTH_PATTERN = "(" + Jsonix.Schema.XSD.Calendar.SINGLE_MONTH_PATTERN + ")" + "(" + Jsonix.Schema.XSD.Calendar.TIMEZONE_PATTERN + ")?";
Jsonix.Schema.XSD.Calendar.GDAY_PATTERN = "(" + Jsonix.Schema.XSD.Calendar.SINGLE_DAY_PATTERN + ")" + "(" + Jsonix.Schema.XSD.Calendar.TIMEZONE_PATTERN + ")?";
Jsonix.Schema.XSD.Calendar.GYEAR_MONTH_PATTERN = "(" + Jsonix.Schema.XSD.Calendar.YEAR_PATTERN + ")" + "-" + "(" + Jsonix.Schema.XSD.Calendar.DAY_PATTERN + ")" + "(" + Jsonix.Schema.XSD.Calendar.TIMEZONE_PATTERN + ")?";

Jsonix.Schema.XSD.Calendar.GMONTH_DAY_SPLITTER = "(" + Jsonix.Schema.XSD.Calendar.SINGLE_MONTH_PATTERN + ")" +"-"+ "(" +Jsonix.Schema.XSD.Calendar.DAY_PATTERN +")" + "(" + Jsonix.Schema.XSD.Calendar.TIMEZONE_PATTERN + ")?";
Jsonix.Schema.XSD.Calendar.GMONTH_DAY_PATTERN = "(" + Jsonix.Schema.XSD.Calendar.SINGLE_MONTH_PATTERN + ")" +"-"+ "(" +Jsonix.Schema.XSD.Calendar.DAY_PATTERN +")" + "(" + Jsonix.Schema.XSD.Calendar.TIMEZONE_PATTERN + ")?";

Jsonix.Schema.XSD.Calendar.INSTANCE = new Jsonix.Schema.XSD.Calendar();
Jsonix.Schema.XSD.Calendar.INSTANCE.LIST = new Jsonix.Schema.XSD.List(Jsonix.Schema.XSD.Calendar.INSTANCE);
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Jsonix.Schema.XSD.GDay = Jsonix.Class(Jsonix.Schema.XSD.Calendar, {
returnValue.toString = function() {
return "EmptyXMLElement. Call embedded 'day' or 'timezone' property";
};

return returnValue;
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ Jsonix.Schema.XSD.GMonthDay = Jsonix.Class(Jsonix.Schema.XSD.Calendar, {
*/
splitGMonthDay : function(value) {

var gMonthDayExpression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.GMONTH_DAY_SPLITTER + "$");
var gMonthDayExpression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.GMONTH_DAY_PATTERN + "$");
var results = value.match(gMonthDayExpression);

if (results !== null) {
var splitedGMonthDay = {

month : parseInt(results[2], 10),
day : parseInt(results[3], 10),
timezone : this.convertTimeZoneString(results[5])
};

var shortMonths = [ 4, 6, 9, 11 ];
var shortMonths = [ 4, 6, 9, 11 ];
var validationFailed = false;

if (splitedGMonthDay.month === 2 && splitedGMonthDay.day > 29) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ Jsonix.Schema.XSD.GYear = Jsonix.Class(Jsonix.Schema.XSD.Calendar, {
year : parseInt(results[1], 10),
timezone : this.convertTimeZoneString(results[5])
};

return splitedGYear;
} else {
throw new Error('Value [' + value + '] does not match the gYear pattern.');
}

throw new Error('Value [' + value + '] doesn\'t match the gYear pattern.');
}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void offset() {
final Date date = new Date(70, 0, 1, 10, 0, 0);


System.out.println(date.getTimezoneOffset());
System.out.println("Timezone offset:" + date.getTimezoneOffset());
System.out.println(date.getTime());

System.out.println(DATATYPE_FACTORY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,13 @@ public void checksGMonthDay() throws DatatypeConfigurationException {
Assert.assertEquals(31,
datatypeFactory.newXMLGregorianCalendar("--02-31").getDay());
}

public void checksDateTime() throws DatatypeConfigurationException {
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();

Assert.assertEquals(
-300,
datatypeFactory.newXMLGregorianCalendar(
"2013-05-07T08:09:10-05:00").getTimezone());
}
}

0 comments on commit 9aa2596

Please sign in to comment.