Skip to content

Commit

Permalink
Update for last commit to allow standalone time in Finnish to take
Browse files Browse the repository at this point in the history
precedence (#595).
  • Loading branch information
andrewplummer committed Aug 11, 2018
1 parent 9ea510a commit bf511d0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
37 changes: 22 additions & 15 deletions lib/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,20 @@ var CoreParsingFormats = [
// 12/08/1978
// 08/12/1978 (MDY)
time: true,
src: '{dd}[-.\\/]{MM}(?:[-.\\/]{yyyy|yy|y})?',
mdy: '{MM}[-.\\/]{dd}(?:[-.\\/]{yyyy|yy|y})?'
src: '{dd}[-\\/]{MM}(?:[-\\/]{yyyy|yy|y})?',
mdy: '{MM}[-\\/]{dd}(?:[-\\/]{yyyy|yy|y})?'
},
{
// 12.08.1978
// 08.12.1978 (MDY)
time: true,
src: '{dd}\\.{MM}(?:\\.{yyyy|yy|y})?',
mdy: '{MM}\\.{dd}(?:\\.{yyyy|yy|y})?',
localeCheck: function(loc) {
// Do not allow this format if the locale
// uses a period as a time separator.
return loc.timeSeparator !== '.';
}
},
{
// 1975-08-25
Expand Down Expand Up @@ -2369,8 +2381,7 @@ function getNewLocale(def) {
}

function buildTimeFormats() {
loc.parsingAliases['time'] = getTimeFormat();
loc.parsingAliases['timeOnly'] = getTimeFormat(true);
loc.parsingAliases['time'] = getTimeFormat();
loc.parsingAliases['tzOffset'] = getTZOffsetFormat();
}

Expand All @@ -2389,21 +2400,14 @@ function getNewLocale(def) {
return src;
}

function getTimeSeparatorSrc(standalone) {
var sep = loc.timeSeparator;
if (allowsAlternateTimeSeparator(sep, standalone)) {
return '[:' + sep + ']';
function getTimeSeparatorSrc() {
if (loc.timeSeparator) {
return '[:' + loc.timeSeparator + ']';
} else {
return ':';
}
}

function allowsAlternateTimeSeparator(sep, standalone) {
// Don't allow . as a time separator if time is standalone
// as it will interfere with date parsing.
return sep && (!standalone || sep !== '.');
}

function getTZOffsetFormat() {
return '(?:{Z}|{GMT?}(?:{tzHour}(?::?{tzMinute}(?: \\([\\w\\s]+\\))?)?)?)?';
}
Expand Down Expand Up @@ -2473,6 +2477,9 @@ function getNewLocale(def) {
function addCoreFormats() {
forEach(CoreParsingFormats, function(df) {
var src = df.src;
if (df.localeCheck && !df.localeCheck(loc)) {
return;
}
if (df.mdy && loc.mdy) {
// Use the mm/dd/yyyy variant if it
// exists and the locale requires it
Expand All @@ -2487,7 +2494,7 @@ function getNewLocale(def) {
loc.addFormat(src);
}
});
loc.addFormat('{timeOnly}');
loc.addFormat('{time}');
}

function addLocaleFormats() {
Expand Down
5 changes: 4 additions & 1 deletion test/tests/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ namespace('Date', function () {

// Dots
assertDateParsed('08.10.1978', 'en-GB', new Date(1978, 9, 8));
assertDateParsed('8.10.1978', 'en-GB', new Date(1978, 9, 8));
assertDateParsed('8.10.1978', 'en-GB', new Date(1978, 9, 8));
assertDateParsed('8.10', 'en-GB', new Date(thisYear, 9, 8));
assertDateParsed('1978.8.10', 'en-GB', new Date(1978, 7, 10));
assertDateParsed('10.1978', 'en-GB', new Date(1978, 9, 1));

assertDateParsed('08-05-05', 'en-GB', new Date(2005, 4, 8));
assertDateParsed('8/10/85', new Date(1985, 7, 10));
Expand Down
4 changes: 4 additions & 0 deletions test/tests/locales/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ namespace('Date | Finnish', function () {

assertDateParsed('torstaina 5. tammikuuta 2012 kello 15:45', new Date(2012, 0, 5, 15, 45));

// Standalone time format.
assertDateParsed('3.45', new Date(now.getFullYear(), now.getMonth(), now.getDate(), 3, 45));


assertDateParsed('tammikuu', new Date(now.getFullYear(), 0));
assertDateParsed('helmikuu', new Date(now.getFullYear(), 1));
assertDateParsed('maaliskuu', new Date(now.getFullYear(), 2));
Expand Down

0 comments on commit bf511d0

Please sign in to comment.