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
875c19cd
Commit
875c19cd
authored
Jun 26, 2014
by
Johannes Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfixing
parent
b58db5f7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
28 deletions
+51
-28
holidays.js
holidays.js
+11
-5
jsonInput.js
jsonInput.js
+32
-23
timeUtils.js
timeUtils.js
+8
-0
No files found.
holidays.js
View file @
875c19cd
...
...
@@ -52,9 +52,7 @@ function Holidays(year) {
var
dateString
=
fixedHolidays
[
key
];
var
date
=
parseInt
(
dateString
.
slice
(
0
,
2
));
var
month
=
parseInt
(
dateString
.
slice
(
2
,
4
));
console
.
log
(
date
,
month
);
result
[
key
]
=
new
Date
(
year
,
month
-
1
,
date
);
console
.
log
(
result
[
key
]);
}
return
result
;
}
...
...
@@ -69,10 +67,18 @@ function Holidays(year) {
return
result
;
}
console
.
log
(
getFixedHolidays
(
fixedHolidays
));
console
.
log
(
getVariableHolidaysMap
(
variableOffsets
));
var
holidays
=
getFixedHolidays
(
fixedHolidays
);
var
holidays
=
getVariableHolidaysMap
(
variableOffsets
,
holidays
);
this
.
getHoliday
=
function
(
id
)
{
if
(
id
in
holidays
)
return
holidays
[
id
];
console
.
error
(
"invalid holiday id "
+
id
);
return
null
;
}
}
new
Holidays
(
2014
);
var
holidays
=
new
Holidays
(
2014
);
console
.
log
(
holidays
.
getHoliday
(
2
));
module
.
exports
=
Holidays
;
\ No newline at end of file
jsonInput.js
View file @
875c19cd
...
...
@@ -5,40 +5,48 @@ var includeString = "810a6deb-46f2-4fa8-b779-bb5c2a6b5577";
var
excludeString
=
"bb74c170-b06f-4d2b-ab88-2f6bf9ce8068"
;
var
_epochStart
=
new
Date
();
_epochStart
.
setDate
(
_epochStart
.
getDate
()
-
14
);
var
_epochEnd
=
new
Date
(
_epochStart
.
getTime
()
+
31
*
24
*
3600000
);
_epochStart
.
setDate
(
_epochStart
.
getDate
()
-
14
);
var
_epochEnd
=
new
Date
(
_epochStart
.
getTime
()
+
31
*
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
);
var
result
=
tmUtils
.
andNotOperator
(
resultIncl
,
resultExcl
);
console
.
log
(
process
.
hrtime
(
time0
));
console
.
log
(
result
);
}
function
getHolidays
(
data
)
{
}
function
getIntervals
(
json
)
{
var
result
=
[];
for
(
var
key
in
json
)
{
var
holidays
=
[];
for
(
var
key
in
json
)
{
var
x
=
getOpeningHours
(
json
[
key
]);
if
(
x
)
if
(
x
)
result
.
push
(
x
);
else
{
x
=
getHolidays
(
json
[
key
])
if
(
x
)
holidays
.
push
(
x
);
}
}
return
tmUtils
.
orOperator
(
result
);
}
function
getDaySpan
(
dayoption
)
{
if
(
dayoption
<
7
)
return
[
dayoption
,
dayoption
];
switch
(
dayoption
)
{
if
(
dayoption
<
7
)
return
[
dayoption
,
dayoption
];
switch
(
dayoption
)
{
case
7
:
return
[
0
,
0
];
case
8
:
...
...
@@ -61,29 +69,29 @@ function parseTime(time) {
}
function
parseDate
(
date
,
addOneDay
)
{
if
(
date
.
length
==
0
)
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
])
+
addOneDay
?
1
:
0
;
var
month
=
parseInt
(
split
[
1
])
-
1
;
var
day
=
parseInt
(
split
[
0
])
+
addOneDay
?
1
:
0
;
return
new
Date
(
year
,
month
,
day
);
}
function
getOpeningHours
(
data
)
{
var
dayoption
=
parseInt
(
data
[
"dayoption"
][
"0"
]);
var
daySpan
=
getDaySpan
(
dayoption
);
var
option
=
data
[
"option"
][
"0"
];
var
dayoption
=
parseInt
(
data
[
"dayoption"
][
"0"
]);
var
daySpan
=
getDaySpan
(
dayoption
);
var
startDate
=
parseDate
(
data
[
"opening_day_from"
])
||
_epochStart
;
var
endDate
=
parseDate
(
data
[
"opening_day_to"
],
true
)
||
_epochEnd
;
var
dateSpan
=
[
startDate
,
endDate
];
var
timeSpan
=
[
parseTime
(
data
[
"opening_from"
]),
parseTime
(
data
[
"opening_to"
])];
switch
(
option
)
{
var
result
=
{
type
:
0
};
switch
(
option
)
{
case
"default"
:
return
tmUtils
.
standardFromTillDay
(
daySpan
,
timeSpan
,
epocheSpan
,
7
);
case
"season"
:
...
...
@@ -91,22 +99,23 @@ function getOpeningHours(data) {
case
"repeatable"
:
var
repeatOption
=
parseInt
(
data
[
"repeatoption"
][
"0"
]);
var
noInMonth
;
if
(
repeatOption
<=
4
)
noInMonth
=
repeatOption
;
else
if
(
repeatOption
==
30
)
noInMonth
=
-
1
;
if
(
repeatOption
<=
4
)
noInMonth
=
repeatOption
;
else
if
(
repeatOption
==
30
)
noInMonth
=
-
1
;
if
(
noInMonth
)
if
(
noInMonth
)
return
tmUtils
.
cyclicFromTillDay
(
daySpan
,
noInMonth
,
timeSpan
,
dateSpan
,
epocheSpan
);
switch
(
repeatOption
)
{
switch
(
repeatOption
)
{
case
14
:
case
21
:
case
28
:
return
tmUtils
.
standardFromTillDay
(
daySpan
,
timeSpan
,
dateSpan
,
repeatOption
);
default
:
throw
"invalid repeat option"
;
console
.
error
(
"invalid repeatoption"
)
;
}
}
// throw "invalid data";
}
calculateOpeningHours
(
require
(
'./testData/testHof.json'
));
\ No newline at end of file
timeUtils.js
View file @
875c19cd
...
...
@@ -180,6 +180,14 @@ function _getNextNoInMonthOccurence(day, startDate, noInMonth) {
return
startDate
;
}
/**
* return a timespan on one day, if not timespan is given,
* the whole day is returned
*
* @param date
* @param [timeSpan]
* @returns {*[]}
*/
function
singleDay
(
date
,
timeSpan
)
{
var
startDate
,
endDate
;
if
(
timeSpan
)
{
...
...
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