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
eca9e65e
Commit
eca9e65e
authored
Jun 25, 2014
by
Johannes Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfixing
parent
3b39b87e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
21 deletions
+48
-21
jsonInput.js
jsonInput.js
+21
-18
timeUtils.js
timeUtils.js
+27
-3
No files found.
jsonInput.js
View file @
eca9e65e
...
...
@@ -7,23 +7,26 @@ var excludeString = "bb74c170-b06f-4d2b-ab88-2f6bf9ce8068";
var
_epochStart
=
new
Date
();
_epochStart
.
setDate
(
_epochStart
.
getDate
()
-
14
);
var
_epochEnd
=
new
Date
(
_epochStart
.
getTime
()
+
60
*
24
*
3600000
);
var
epocheSpan
=
[
_epochStart
,
_epochEnd
];
function
calculateOpeningHours
(
json
)
{
var
jsonIncl
=
json
[
includeString
];
var
jsonExcl
=
json
[
excludeString
];
// console.log(jsonExcl);
// console.log(getOpeningHours(jsonExcl[0]));
var
resultIncl
=
getIntervals
(
jsonIncl
);
var
resultExcl
=
getIntervals
(
jsonExcl
);
console
.
log
(
resultIncl
);
console
.
log
(
resultExcl
);
console
.
log
(
tmUtils
.
andNotOperator
(
resultIncl
,
resultExcl
));
}
function
getIntervals
(
json
)
{
function
getIntervals
(
json
)
{
var
result
=
[];
for
(
var
key
in
json
)
{
var
x
=
getOpeningHours
(
json
[
key
]);
...
...
@@ -53,19 +56,19 @@ function getDaySpan(dayoption) {
function
parseTime
(
time
)
{
var
split
=
time
.
split
(
":"
);
return
{
h
:
parseInt
(
split
[
0
]),
m
:
parseInt
(
split
[
1
])
h
:
parseInt
(
split
[
0
])
||
0
,
m
:
parseInt
(
split
[
1
])
||
0
}
}
function
parseDate
(
date
)
{
function
parseDate
(
date
,
addOneDay
)
{
if
(
date
.
length
==
0
)
return
null
;
var
year
=
now
.
getFullYear
();
var
split
=
date
.
split
(
"."
);
var
month
=
parseInt
(
split
[
1
])
-
1
;
var
day
=
parseInt
(
split
[
0
]);
var
day
=
parseInt
(
split
[
0
])
+
addOneDay
?
1
:
0
;
return
new
Date
(
year
,
month
,
day
);
}
...
...
@@ -76,16 +79,16 @@ function getOpeningHours(data) {
var
option
=
data
[
"option"
][
"0"
];
var
startDate
=
parseDate
(
data
[
"opening_day_from"
])
||
_epochStart
;
var
endDate
=
parseDate
(
data
[
"opening_day_to"
])
||
_epochEnd
;
var
endDate
=
parseDate
(
data
[
"opening_day_to"
],
true
)
||
_epochEnd
;
var
dateSpan
=
[
startDate
,
endDate
];
var
timeFrom
=
parseTime
(
data
[
"opening_from"
]);
var
timeTill
=
parseTime
(
data
[
"opening_to"
]);
var
timeSpan
=
[
parseTime
(
data
[
"opening_from"
]),
parseTime
(
data
[
"opening_to"
])];
switch
(
option
)
{
case
"default"
:
return
tmUtils
.
standardFromTillDay
(
daySpan
[
0
],
daySpan
[
1
],
timeFrom
,
timeTill
,
_epochStart
,
_epochEnd
,
7
);
return
tmUtils
.
standardFromTillDay
(
daySpan
,
timeSpan
,
epocheSpan
,
7
);
case
"season"
:
return
tmUtils
.
standardFromTillDay
(
daySpan
[
0
],
daySpan
[
1
],
timeFrom
,
timeTill
,
startDate
,
endDate
,
7
);
return
tmUtils
.
standardFromTillDay
(
daySpan
,
timeSpan
,
dateSpan
,
7
);
case
"repeatable"
:
var
repeatOption
=
parseInt
(
data
[
"repeatoption"
][
"0"
]);
var
noInMonth
;
...
...
@@ -93,13 +96,13 @@ function getOpeningHours(data) {
else
if
(
repeatOption
==
30
)
noInMonth
=
-
1
;
if
(
noInMonth
)
return
tmUtils
.
cyclicFromTillDay
(
daySpan
[
0
],
daySpan
[
1
],
noInMonth
,
timeFrom
,
timeTill
,
startDate
,
endDate
);
return
tmUtils
.
cyclicFromTillDay
(
daySpan
,
noInMonth
,
timeSpan
,
dateSpan
,
epocheSpan
);
switch
(
repeatOption
)
{
switch
(
repeatOption
)
{
case
14
:
case
21
:
case
28
:
return
tmUtils
.
standardFromTillDay
(
daySpan
[
0
],
daySpan
[
1
],
timeFrom
,
timeTill
,
startDate
,
endDate
,
repeatOption
);
return
tmUtils
.
standardFromTillDay
(
daySpan
,
timeSpan
,
dateSpan
,
repeatOption
);
default
:
throw
"invalid repeat option"
;
}
...
...
@@ -107,4 +110,4 @@ function getOpeningHours(data) {
// throw "invalid data";
}
calculateOpeningHours
(
require
(
'./testData/hofman.json'
));
\ No newline at end of file
calculateOpeningHours
(
require
(
'./testData/testHof.json'
));
\ No newline at end of file
timeUtils.js
View file @
eca9e65e
...
...
@@ -6,7 +6,7 @@ function compareFT(from, till) {
}
function
transformTill
(
from
,
till
)
{
if
(
compareFT
(
from
,
till
)
>
0
)
{
if
(
compareFT
(
from
,
till
)
>
=
0
)
{
return
{
h
:
till
.
h
+
24
,
m
:
till
.
m
}
}
else
return
till
;
...
...
@@ -34,7 +34,14 @@ function _standard(day, timeFrom, timeUntil, epochStart, epochEnd, distanceDays)
return
_cyclicInterval
(
startDate
,
endDate
,
distanceDays
*
24
*
3600000
,
epochStart
,
epochEnd
);
}
function
standardFromTillDay
(
dayFrom
,
dayTill
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
,
daysDistance
)
{
function
standardFromTillDay
(
daySpan
,
timeSpan
,
dateSpan
,
daysDistance
)
{
var
dayFrom
=
daySpan
[
0
];
var
dayTill
=
daySpan
[
1
];
var
timeFrom
=
timeSpan
[
0
];
var
timeUntil
=
timeSpan
[
1
];
var
epochStart
=
dateSpan
[
0
];
var
epochEnd
=
dateSpan
[
1
];
timeUntil
=
transformTill
(
timeFrom
,
timeUntil
);
var
firstDays
=
_standard
(
dayFrom
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
,
daysDistance
);
...
...
@@ -77,7 +84,22 @@ function cyclic(day, noInMonth, timeFrom, timeUntil, epochStart, epochEnd) {
return
result
;
}
function
cyclicFromTillDay
(
dayFrom
,
dayTill
,
noInMonth
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
)
{
function
cyclicFromTillDay
(
daySpan
,
noInMonth
,
timeSpan
,
dateSpan
,
epochSpan
)
{
var
dayFrom
=
daySpan
[
0
];
var
dayTill
=
daySpan
[
1
];
var
timeFrom
=
timeSpan
[
0
];
var
timeUntil
=
timeSpan
[
1
];
var
epochStart
=
dateSpan
[
0
];
var
epochEnd
=
dateSpan
[
1
];
//limit dateSpan to epochSpan, to reduce costs
if
(
epochEnd
>
epochSpan
[
1
])
epochEnd
=
epochSpan
[
1
];
if
(
epochStart
<
epochSpan
[
0
])
{
var
t
=
epochSpan
[
0
];
//substract 1 month to cover special cases
epochStart
=
new
Date
(
t
.
getFullYear
(),
t
.
getMonth
()
-
1
,
t
.
getDate
())
}
timeUntil
=
transformTill
(
timeFrom
,
timeUntil
);
var
result
=
[];
epochStart
=
new
Date
(
epochStart
);
...
...
@@ -106,6 +128,8 @@ function cyclicFromTillDay(dayFrom, dayTill, noInMonth, timeFrom, timeUntil, epo
}
}
}
result
=
andOperator
(
result
,
[
epochSpan
]);
return
result
;
}
...
...
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