parent
ee72a200e1
commit
109956d235
@ -1021,7 +1021,7 @@ SchemaAlignment._initField = function(inputContainer, mode, initialValue, change
|
|||||||
changedCallback();
|
changedCallback();
|
||||||
});
|
});
|
||||||
|
|
||||||
SchemaAlignment.setupStringInputValidation(input, /^((\d{4}(-[0-1]\d(-[0-3]\d)?)?)|TODAY)$/);
|
SchemaAlignment.setupStringInputValidation(input, /^(([\-]?\d{4}(-[0-1]\d(-[0-3]\d)?)?)|TODAY)$/);
|
||||||
} else if (mode === "globe-coordinate") {
|
} else if (mode === "globe-coordinate") {
|
||||||
input.attr("placeholder", "lat,lon");
|
input.attr("placeholder", "lat,lon");
|
||||||
var propagateValue = function(val) {
|
var propagateValue = function(val) {
|
||||||
|
@ -104,6 +104,7 @@ public class WbDateConstant implements WbExpression<TimeValue> {
|
|||||||
Date bestDate = null;
|
Date bestDate = null;
|
||||||
int precision = 0; // default precision (will be overridden if successfully parsed)
|
int precision = 0; // default precision (will be overridden if successfully parsed)
|
||||||
int maxLength = 0; // the maximum length parsed
|
int maxLength = 0; // the maximum length parsed
|
||||||
|
boolean bceFlag = false; // judge whether this is a BCE year
|
||||||
String calendarIri = TimeValue.CM_GREGORIAN_PRO; // Gregorian calendar is assumed by default
|
String calendarIri = TimeValue.CM_GREGORIAN_PRO; // Gregorian calendar is assumed by default
|
||||||
|
|
||||||
String trimmedDatestamp = datestamp.trim();
|
String trimmedDatestamp = datestamp.trim();
|
||||||
@ -118,6 +119,10 @@ public class WbDateConstant implements WbExpression<TimeValue> {
|
|||||||
return todaysDate;
|
return todaysDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(trimmedDatestamp.startsWith("-")){
|
||||||
|
trimmedDatestamp = trimmedDatestamp.substring(1);
|
||||||
|
bceFlag = true;
|
||||||
|
}
|
||||||
|
|
||||||
for (Entry<SimpleDateFormat, Integer> entry : acceptedFormats.entrySet()) {
|
for (Entry<SimpleDateFormat, Integer> entry : acceptedFormats.entrySet()) {
|
||||||
ParsePosition position = new ParsePosition(0);
|
ParsePosition position = new ParsePosition(0);
|
||||||
@ -155,7 +160,10 @@ public class WbDateConstant implements WbExpression<TimeValue> {
|
|||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar = Calendar.getInstance();
|
calendar = Calendar.getInstance();
|
||||||
calendar.setTime(bestDate);
|
calendar.setTime(bestDate);
|
||||||
return Datamodel.makeTimeValue(calendar.get(Calendar.YEAR), (byte) (calendar.get(Calendar.MONTH) + 1),
|
long year = calendar.get(Calendar.YEAR);
|
||||||
|
if(bceFlag)
|
||||||
|
year = -1*year;
|
||||||
|
return Datamodel.makeTimeValue(year, (byte) (calendar.get(Calendar.MONTH) + 1),
|
||||||
(byte) calendar.get(Calendar.DAY_OF_MONTH), (byte) calendar.get(Calendar.HOUR_OF_DAY),
|
(byte) calendar.get(Calendar.DAY_OF_MONTH), (byte) calendar.get(Calendar.HOUR_OF_DAY),
|
||||||
(byte) calendar.get(Calendar.MINUTE), (byte) calendar.get(Calendar.SECOND), (byte) precision, 0, 0,
|
(byte) calendar.get(Calendar.MINUTE), (byte) calendar.get(Calendar.SECOND), (byte) precision, 0, 0,
|
||||||
0, calendarIri);
|
0, calendarIri);
|
||||||
|
@ -47,6 +47,21 @@ public class WbDateConstantTest extends WbExpressionTest<TimeValue> {
|
|||||||
private WbDateConstant julianYear = new WbDateConstant("1324_Q1985786");
|
private WbDateConstant julianYear = new WbDateConstant("1324_Q1985786");
|
||||||
private WbDateConstant julianDecade = new WbDateConstant("1320D_Q1985786");
|
private WbDateConstant julianDecade = new WbDateConstant("1320D_Q1985786");
|
||||||
|
|
||||||
|
private WbDateConstant BCEmillenium = new WbDateConstant("-1001M");
|
||||||
|
private WbDateConstant BCEcentury = new WbDateConstant("-1701C");
|
||||||
|
private WbDateConstant BCEdecade = new WbDateConstant("-1990D");
|
||||||
|
private WbDateConstant BCEyear = new WbDateConstant("-2018");
|
||||||
|
private WbDateConstant BCEmonth = new WbDateConstant("-2018-02");
|
||||||
|
private WbDateConstant BCEday = new WbDateConstant("-2018-02-27");
|
||||||
|
private WbDateConstant BCEwhitespace = new WbDateConstant(" -2018-02-27 ");
|
||||||
|
private WbDateConstant BCEsecond = new WbDateConstant("-2017-01-03T04:12:45");
|
||||||
|
private WbDateConstant BCEsecondz = new WbDateConstant("-2017-01-03T04:12:45Z");
|
||||||
|
|
||||||
|
private WbDateConstant BCEjulianDay = new WbDateConstant("-1324-02-27_Q1985786");
|
||||||
|
private WbDateConstant BCEjulianMonth = new WbDateConstant("-1324-02_Q1985786");
|
||||||
|
private WbDateConstant BCEjulianYear = new WbDateConstant("-1324_Q1985786");
|
||||||
|
private WbDateConstant BCEjulianDecade = new WbDateConstant("-1320D_Q1985786");
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() {
|
public void testSerialize() {
|
||||||
@ -89,6 +104,38 @@ public class WbDateConstantTest extends WbExpressionTest<TimeValue> {
|
|||||||
TimeValue.CM_JULIAN_PRO), julianDay);
|
TimeValue.CM_JULIAN_PRO), julianDay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEvaluateBCE() {
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-1001, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 6, 0, 0, 0,
|
||||||
|
TimeValue.CM_GREGORIAN_PRO), BCEmillenium);
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-1701, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 7, 0, 0, 0,
|
||||||
|
TimeValue.CM_GREGORIAN_PRO), BCEcentury);
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-1990, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 8, 0, 0, 0,
|
||||||
|
TimeValue.CM_GREGORIAN_PRO), BCEdecade);
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-2018, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 9, 0, 0, 0,
|
||||||
|
TimeValue.CM_GREGORIAN_PRO), BCEyear);
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-2018, (byte) 2, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 10, 0, 0, 0,
|
||||||
|
TimeValue.CM_GREGORIAN_PRO), BCEmonth);
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-2018, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
|
||||||
|
TimeValue.CM_GREGORIAN_PRO), BCEday);
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-2017, (byte) 1, (byte) 3, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
|
||||||
|
TimeValue.CM_GREGORIAN_PRO), BCEsecond);
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-2017, (byte) 1, (byte) 3, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
|
||||||
|
TimeValue.CM_GREGORIAN_PRO), BCEsecondz);
|
||||||
|
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-2018, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
|
||||||
|
TimeValue.CM_GREGORIAN_PRO), BCEwhitespace);
|
||||||
|
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-1320, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 8, 0, 0, 0,
|
||||||
|
TimeValue.CM_JULIAN_PRO), BCEjulianDecade);
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-1324, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 9, 0, 0, 0,
|
||||||
|
TimeValue.CM_JULIAN_PRO), BCEjulianYear);
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-1324, (byte) 2, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 10, 0, 0, 0,
|
||||||
|
TimeValue.CM_JULIAN_PRO), BCEjulianMonth);
|
||||||
|
evaluatesTo(Datamodel.makeTimeValue(-1324, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
|
||||||
|
TimeValue.CM_JULIAN_PRO), BCEjulianDay);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToday() {
|
public void testToday() {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
Loading…
Reference in New Issue
Block a user