Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
opening-hours
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
regionalkauf
opening-hours
Commits
611f1301
Commit
611f1301
authored
Oct 26, 2015
by
Johannes Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added datespan option, splitted dates over midnight
parent
73889a29
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
2 deletions
+49
-2
dateArray.js
lib/dateArray.js
+15
-0
dateView.js
lib/dateView.js
+5
-2
timeUtils.js
lib/timeUtils.js
+29
-0
No files found.
lib/dateArray.js
View file @
611f1301
...
@@ -119,6 +119,8 @@ function wrapper(_epochSpan) {
...
@@ -119,6 +119,8 @@ function wrapper(_epochSpan) {
if
(
jsonExcl
)
if
(
jsonExcl
)
result
=
tmUtils
.
andNotOp
(
resultIncl
,
resultExcl
);
result
=
tmUtils
.
andNotOp
(
resultIncl
,
resultExcl
);
//result = tmUtils.splitMidnight(result);
return
result
;
return
result
;
}
}
...
@@ -258,6 +260,8 @@ function wrapper(_epochSpan) {
...
@@ -258,6 +260,8 @@ function wrapper(_epochSpan) {
return
getOpeningHoursRepeatable
(
data
);
return
getOpeningHoursRepeatable
(
data
);
case
"vacation"
:
case
"vacation"
:
return
getOpeningHoursVacation
(
data
);
return
getOpeningHoursVacation
(
data
);
case
"datespan"
:
return
getOpeningHoursDatespan
(
data
);
case
""
:
case
""
:
return
[];
return
[];
default
:
default
:
...
@@ -281,6 +285,17 @@ function wrapper(_epochSpan) {
...
@@ -281,6 +285,17 @@ function wrapper(_epochSpan) {
}));
}));
}
}
function
getOpeningHoursDatespan
(
data
)
{
var
from
=
new
Date
(
data
[
'opening_date_from'
]);
var
to
=
new
Date
(
data
[
'opening_date_to'
]);
if
(
!
from
||
!
to
)
{
console
.
error
(
new
Error
(
'invalid data for datespan option '
+
JSON
.
stringify
(
data
)))
}
else
{
return
[[
from
,
to
]];
}
}
function
getOpeningHoursVacation
(
data
)
{
function
getOpeningHoursVacation
(
data
)
{
if
(
data
[
"opening_day_from"
]
==
""
||
data
[
"opening_day_to"
]
==
""
)
{
if
(
data
[
"opening_day_from"
]
==
""
||
data
[
"opening_day_to"
]
==
""
)
{
console
.
error
(
new
Error
(
"opening_day cant be empty in vacations"
));
console
.
error
(
new
Error
(
"opening_day cant be empty in vacations"
));
...
...
lib/dateView.js
View file @
611f1301
var
moment
=
require
(
'moment'
);
var
moment
=
require
(
'moment'
);
var
tmUtils
=
require
(
'./timeUtils'
);
var
maybeString
=
"nach Absprache geöffnet"
;
var
maybeString
=
"nach Absprache geöffnet"
;
var
andMaybeString
=
"und nach Absprache geöffnet"
;
var
andMaybeString
=
"und nach Absprache geöffnet"
;
//var maybeString = "nag";
//var maybeString = "nag";
...
@@ -489,6 +489,10 @@ function weekViewData(dataObj, now) {
...
@@ -489,6 +489,10 @@ function weekViewData(dataObj, now) {
}
}
function
transformData
(
dataObj
,
startDate
,
endDate
)
{
function
transformData
(
dataObj
,
startDate
,
endDate
)
{
dataObj
.
intervals
=
tmUtils
.
splitMidnight
(
dataObj
.
intervals
);
dataObj
.
maybeIntervals
=
tmUtils
.
splitMidnight
(
dataObj
.
maybeIntervals
);
var
data
=
dataObj
.
intervals
.
map
(
function
(
e
)
{
var
data
=
dataObj
.
intervals
.
map
(
function
(
e
)
{
return
e
;
return
e
;
/* return {
/* return {
...
@@ -555,7 +559,6 @@ function transformData(dataObj, startDate, endDate) {
...
@@ -555,7 +559,6 @@ function transformData(dataObj, startDate, endDate) {
var
isHoliday
=
false
;
var
isHoliday
=
false
;
while
(
holidayIdx
<
holidays
.
length
)
{
while
(
holidayIdx
<
holidays
.
length
)
{
var
comp
=
compareDate
(
holidays
[
holidayIdx
],
curDate
);
var
comp
=
compareDate
(
holidays
[
holidayIdx
],
curDate
);
//TODO: split midnight
if
(
comp
<
0
)
if
(
comp
<
0
)
holidayIdx
++
;
holidayIdx
++
;
else
if
(
comp
==
0
)
{
else
if
(
comp
==
0
)
{
...
...
lib/timeUtils.js
View file @
611f1301
"use strict"
;
var
assert
=
require
(
'assert'
);
var
assert
=
require
(
'assert'
);
var
moment
=
require
(
'moment'
);
function
compareTimeSpan
(
timeSpan
)
{
function
compareTimeSpan
(
timeSpan
)
{
var
from
=
timeSpan
[
0
];
var
from
=
timeSpan
[
0
];
...
@@ -307,6 +310,31 @@ function validate(interval) {
...
@@ -307,6 +310,31 @@ function validate(interval) {
}
}
}
}
function
splitSingleInterval
(
interval
)
{
var
res
=
[];
var
from
=
new
Date
(
interval
[
0
]);
var
to
=
new
Date
(
interval
[
1
]);
var
endOfDay
=
new
Date
(
from
.
getFullYear
(),
from
.
getMonth
(),
from
.
getDate
()
+
1
);
while
(
endOfDay
<
to
)
{
res
.
push
([
from
,
endOfDay
]);
from
=
endOfDay
;
endOfDay
=
new
Date
(
from
.
getFullYear
(),
from
.
getMonth
(),
from
.
getDate
()
+
1
);
}
res
.
push
([
from
,
to
]);
return
res
;
}
function
splitMidnight
(
intervals
)
{
var
res
=
[];
for
(
let
interval
of
intervals
)
{
var
subRes
=
splitSingleInterval
(
interval
);
for
(
let
sub
of
subRes
)
{
res
.
push
(
sub
);
}
}
return
res
;
}
module
.
exports
.
standardFromTillDay
=
standardFromTillDay
;
module
.
exports
.
standardFromTillDay
=
standardFromTillDay
;
module
.
exports
.
cyclicFromTillDay
=
cyclicFromTillDay
;
module
.
exports
.
cyclicFromTillDay
=
cyclicFromTillDay
;
module
.
exports
.
singleDay
=
singleDay
;
module
.
exports
.
singleDay
=
singleDay
;
...
@@ -317,3 +345,4 @@ module.exports.mergeOverlaps = mergeOverlaps;
...
@@ -317,3 +345,4 @@ module.exports.mergeOverlaps = mergeOverlaps;
module
.
exports
.
sort
=
sort
;
module
.
exports
.
sort
=
sort
;
module
.
exports
.
dateSpan
=
dateSpan
;
module
.
exports
.
dateSpan
=
dateSpan
;
module
.
exports
.
validate
=
validate
;
module
.
exports
.
validate
=
validate
;
module
.
exports
.
splitMidnight
=
splitMidnight
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment