in trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js [1453:1622]
TrDateTimeConverter.prototype._simpleDateParseImpl = function(
parseString,
parsePattern,
localeSymbols,
locale,
invalidFormatMsg,
invalidDateMsg)
{
// When a pattern (e.g. dd.MM.yyyy HH:mm' Uhr ') requires a whitespace
// at the end, we should honor that. As the JSF spec (see http://bit.ly/kTelf)
// wants the converter to trim leading/trailing whitespace, we have to append
// one, if the pattern requires it at the end...
if(this._endsWith(parsePattern, " '"))
{
parseString += " ";
}
var parseContext = new Object();
parseContext.currIndex = 0;
parseContext.parseString = parseString;
parseContext.parsedHour = null;
parseContext.parsedMinutes = null;
parseContext.parsedSeconds = null;
parseContext.parsedMilliseconds = null;
parseContext.isPM = false;
parseContext.parsedBC = false;
parseContext.parsedFullYear = null;
parseContext.parsedMonth = null;
parseContext.parsedDate = null;
parseContext.hourOffset = null;
parseContext.minOffset = null;
parseContext.parsedDayOfYear = null;
var parsedTime = new Date(0);
parsedTime.setDate(1);
// parse the time
if (_doClumping(parsePattern,
localeSymbols,
locale,
_subparse,
parseContext,
parsedTime))
{
if (parseString.length != parseContext.currIndex)
{
parseContext.parseException = new TrConverterException (invalidFormatMsg);
throw parseContext.parseException;
}
// give up instantly if we encounter timezone because
// the client can never correctly convert to a milliseconds
// value accurately due to lack of timezone and Daylight savings
// rules in Javascript
// Undefined is used in _multiValidate as a flag to skip
// validation and avoid required errors (which returning null would trigger)
if ((parseContext.hourOffset != null) ||
(parseContext.minOffset != null))
return undefined;
// Set the parsed year, if any; adjust for AD vs. BC
var year = parseContext.parsedFullYear;
if (year != null)
{
// convert year to BC
if (parseContext.parsedBC)
{
year = _getADEra().getFullYear() - year;
}
parsedTime.setFullYear(year);
parseContext.parsedFullYear = year;
}
// Some placeholders require information from other, if available. Process those here.
// e.g. 'D' - day of year, depends if the year is a leap year.
if (parseContext.parsedDayOfYear != null)
{
// Give precedence to date and month, process day of year only if they are not set
if ((parseContext.parsedDate == null) || (parseContext.parsedMonth == null))
{
// If parse string does not contain year, default to current year
//
// Thai Buddhist Calendar uses the same months as Gregorian, so we use the Gregorian equivalent of the Thai
// year (stored in parsedFullYear) to look up the month array
var year = (parseContext.parsedFullYear != null) ? parseContext.parsedFullYear : new Date().getFullYear();
var lastDayOfYearByMonArray = _isLeapYear (year) ? _GREGORIAN_MONTHS_LASTDAYOFYEAR_LEAP:
_GREGORIAN_MONTHS_LASTDAYOFYEAR_NONLEAP;
var monIndx = 0;
for (monIndx = 0; monIndx < 12; monIndx++)
{
if (parseContext.parsedDayOfYear < lastDayOfYearByMonArray[monIndx])
break;
}
parseContext.parsedMonth = monIndx;
// For the first month, date and day_of_year are the same
if (monIndx == 0)
parseContext.parsedDate = parseContext.parsedDayOfYear;
else
parseContext.parsedDate = (parseContext.parsedDayOfYear - lastDayOfYearByMonArray [monIndx - 1]);
}
}
// Set the parsed month, if any
var month = parseContext.parsedMonth;
if (month != null)
parsedTime.setMonth(month);
// Set the parsed day-of-month, if any
var date = parseContext.parsedDate;
if (date != null)
parsedTime.setDate(date);
// Set the parsed hour, if any. Adjust for AM vs. PM
var hour = parseContext.parsedHour;
if (hour != null)
{
if (parseContext.isPM && (hour < 12))
{
hour += 12;
}
parsedTime.setHours(hour);
parseContext.parsedHour = hour;
}
// Set the parsed minutes, if any
var minutes = parseContext.parsedMinutes;
if (minutes != null)
parsedTime.setMinutes(minutes);
// Set the parsed seconds, if any
var seconds = parseContext.parsedSeconds;
if (seconds != null)
parsedTime.setSeconds(seconds);
// Set the parsed milliseconds, if any
var milliseconds = parseContext.parsedMilliseconds;
if (milliseconds != null)
parsedTime.setMilliseconds(milliseconds);
// so far we have done a lenient parse
// now we check for strictness
if (!_isStrict(parseContext, parsedTime))
{
// Trinidad-1634: If the format is correct, but the date doesn't
// match, throw a different error.
parseContext.parseException = new TrConverterException (invalidDateMsg);
parseContext.parseException.isDateInvalid = true;
throw parseContext.parseException;
}
//correct Date Time ?
if(this._offset)
{
var min = parsedTime.getMinutes();
parsedTime.setMinutes((+min) + parseInt(this._offset));
}
return parsedTime;
}
else
{
// failure
parseContext.parseException = new TrConverterException (invalidFormatMsg);
throw parseContext.parseException;
}
}