[gnome-maps/wip/mlundblad/accept-extra-space-openinghours-interval] translations: Handle an extra space between time intervals
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/accept-extra-space-openinghours-interval] translations: Handle an extra space between time intervals
- Date: Mon, 15 Feb 2021 21:43:01 +0000 (UTC)
commit b51deb0849bc8e65491d3bdc43833e6a6af09a5f
Author: Marcus Lundblad <ml update uu se>
Date: Mon Feb 15 22:40:52 2021 +0100
translations: Handle an extra space between time intervals
Handle OSM opening hour specifications of the form:
Mo-Fr 09:00-12:00, 13:00-18:00
with an extra space between time intervals.
src/translations.js | 10 +++++++---
tests/translationsTest.js | 23 +++++++++++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/src/translations.js b/src/translations.js
index be16f0d4..f3943823 100644
--- a/src/translations.js
+++ b/src/translations.js
@@ -72,14 +72,18 @@ function translateOpeningHours(string) {
*/
function _translateOpeningHoursPart(string) {
let splitString = string.split(/\s+/);
+ let len = splitString.length;
- if (splitString.length === 1) {
+ if (len === 1) {
return [_translateOpeningHoursTimeIntervalList(string.trim())];
- } else if (splitString.length === 2) {
+ } else if (len === 2 || len === 3) {
let dayIntervalSpec =
_translateOpeningHoursDayIntervalList(splitString[0].trim());
+ let intervalString =
+ len === 2 ? splitString[1].trim() :
+ splitString[1].trim() + splitString[2].trim();
let timeIntervalSpec =
- _translateOpeningHoursTimeIntervalList(splitString[1].trim());
+ _translateOpeningHoursTimeIntervalList(intervalString);
return [Utils.firstToLocaleUpperCase(dayIntervalSpec),
timeIntervalSpec];
diff --git a/tests/translationsTest.js b/tests/translationsTest.js
index ac662f7f..ce7d7009 100644
--- a/tests/translationsTest.js
+++ b/tests/translationsTest.js
@@ -48,6 +48,11 @@ const SAMPLE8 = 'Mo-Fr 09:00-12:00,13:00-18:00; Sa,Su 10:00-14:00; PH off';
// sample with school holidays
const SAMPLE9 = 'Mo-Fr 09:00-12:00,13:00-18:00; Sa,Su 10:00-14:00; SH off';
+/* sample with 2 components, one day-range, one two day set,
+ * one with 2 time intervals, with an extra space between time components
+ */
+const SAMPLE10 = 'Mo-Fr 09:00-12:00, 13:00-18:00; Sa,Su 10:00-14:00';
+
pkg.initGettext();
pkg.initFormat();
@@ -140,6 +145,15 @@ function translateOpeningHoursTest() {
JsUnit.assertEquals('School holidays', translated[2][0]);
JsUnit.assertEquals('not open', translated[2][1]);
+ translated = Translations.translateOpeningHours(SAMPLE10);
+ JsUnit.assertEquals(2, translated.length);
+ JsUnit.assertEquals(2, translated[0].length);
+ JsUnit.assertEquals('Mon-Fri', translated[0][0]);
+ JsUnit.assertEquals('09:00-12:00, 13:00-18:00', translated[0][1]);
+ JsUnit.assertEquals(2, translated[1].length);
+ JsUnit.assertEquals('Sat,Sun', translated[1][0]);
+ JsUnit.assertEquals('10:00-14:00', translated[1][1]);
+
// mock to always use 12-hour clock format
Time._is12Hour = function () { return true; };
@@ -223,4 +237,13 @@ function translateOpeningHoursTest() {
JsUnit.assertEquals(2, translated[2].length);
JsUnit.assertEquals('School holidays', translated[2][0]);
JsUnit.assertEquals('not open', translated[2][1]);
+
+ translated = Translations.translateOpeningHours(SAMPLE10);
+ JsUnit.assertEquals(2, translated.length);
+ JsUnit.assertEquals(2, translated[0].length);
+ JsUnit.assertEquals('Mon-Fri', translated[0][0]);
+ JsUnit.assertEquals('9:00 AM-12:00 PM, 1:00 PM-6:00 PM', translated[0][1]);
+ JsUnit.assertEquals(2, translated[1].length);
+ JsUnit.assertEquals('Sat,Sun', translated[1][0]);
+ JsUnit.assertEquals('10:00 AM-2:00 PM', translated[1][1]);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]