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
a3d232ce
Commit
a3d232ce
authored
Jun 24, 2014
by
Johannes Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored
parent
fd4c0558
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
12 deletions
+33
-12
test.js
test.js
+10
-7
timeUtils.js
timeUtils.js
+23
-5
No files found.
test.js
View file @
a3d232ce
...
...
@@ -2,14 +2,12 @@ var utils = require('./timeUtils');
//gibt zu betrachtenden Zeitraum an.
var
_epochStart
=
new
Date
(
2014
,
5
,
24
,
0
);
var
_epochEnd
=
new
Date
(
_epochStart
.
getTime
()
+
10
0
*
24
*
3600000
);
var
_epochEnd
=
new
Date
(
_epochStart
.
getTime
()
+
6
0
*
24
*
3600000
);
console
.
log
(
"epochStart"
,
_epochStart
);
console
.
log
(
"epochEnd "
,
_epochEnd
);
//test
//var a = _cyclicInterval(new Date(2014, 5, 23, 9), new Date(2014, 5, 23, 14), 7 * 24 * 3600 * 1000);
//var b = _cyclicInterval(new Date(2014, 5, 23, 10), new Date(2014, 5, 23, 18), 7 * 24 * 3600 * 1000);
//var c = [[new Date(2014, 5, 23, 13), new Date(2014, 6, 6, 10)]];
//var x = andNotOperator(a, b);
//var y = andNotOperator(a, c);
...
...
@@ -19,8 +17,13 @@ console.log("epochEnd ", _epochEnd);
//console.log(workday);
var
t
=
utils
.
cyclicFromTillDay
(
1
,
5
,
-
1
,
{
h
:
9
,
m
:
0
},
{
h
:
18
,
m
:
29
},
_epochStart
,
_epochEnd
);
var
t2
=
utils
.
cyclicFromTillDay
(
2
,
2
,
-
1
,
{
h
:
9
,
m
:
0
},
{
h
:
18
,
m
:
29
},
_epochStart
,
_epochEnd
);
var
res
=
utils
.
andNotOperator
(
t
,
t2
);
var
t1
=
utils
.
cyclicFromTillDay
(
1
,
1
,
1
,
{
h
:
9
,
m
:
0
},
{
h
:
0
,
m
:
0
},
_epochStart
,
_epochEnd
);
var
t2
=
utils
.
cyclicFromTillDay
(
2
,
2
,
1
,
{
h
:
0
,
m
:
0
},
{
h
:
18
,
m
:
29
},
_epochStart
,
_epochEnd
);
console
.
log
(
res
);
\ No newline at end of file
console
.
log
(
t1
);
console
.
log
(
t2
);
var
t
=
utils
.
orOperator
([
t1
,
t2
]);
console
.
log
(
t
);
console
.
log
(
utils
.
mergeOverlaps
(
t
));
//console.log(utils.orOperator([t,t2]));
\ No newline at end of file
timeUtils.js
View file @
a3d232ce
function
compareFT
(
from
,
till
)
{
if
(
from
.
h
==
till
.
h
)
return
from
.
m
-
till
.
m
;
else
return
from
.
h
-
till
.
h
}
function
transformTill
(
from
,
till
)
{
if
(
compareFT
(
from
,
till
)
>
0
)
{
return
{
h
:
till
.
h
+
24
,
m
:
till
.
m
}
}
else
return
till
;
}
function
_cyclicInterval
(
from
,
until
,
interval
,
epochStart
,
epochEnd
)
{
if
(
from
>=
until
)
throw
new
Error
(
"startDate cant be greater than endDate"
);
var
resultArray
=
[];
...
...
@@ -7,7 +21,7 @@ function _cyclicInterval(from, until, interval, epochStart, epochEnd) {
return
resultArray
;
}
function
standard
(
day
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
,
distanceDays
)
{
function
_
standard
(
day
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
,
distanceDays
)
{
var
dayDiff
=
day
-
epochStart
.
getDay
();
if
(
dayDiff
<
0
)
dayDiff
+=
7
;
...
...
@@ -21,7 +35,9 @@ function standard(day, timeFrom, timeUntil, epochStart, epochEnd, distanceDays)
}
function
standardFromTillDay
(
dayFrom
,
dayTill
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
,
distanceDays
)
{
var
firstDays
=
standard
(
dayFrom
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
,
distanceDays
);
timeUntil
=
transformTill
(
timeFrom
,
timeUntil
);
var
firstDays
=
_standard
(
dayFrom
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
,
distanceDays
);
var
result
=
firstDays
.
slice
();
for
(
var
offset
=
1
;
offset
<=
dayTill
-
dayFrom
;
offset
++
)
{
...
...
@@ -60,7 +76,9 @@ function cyclic(day, noInMonth, timeFrom, timeUntil, epochStart, epochEnd) {
}
return
result
;
}
function
cyclicFromTillDay
(
dayFrom
,
dayTill
,
noInMonth
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
)
{
timeUntil
=
transformTill
(
timeFrom
,
timeUntil
);
var
result
=
[];
epochStart
=
new
Date
(
epochStart
);
...
...
@@ -154,13 +172,13 @@ function sortDateIntervals(intervals) {
return
intervals
;
}
function
remov
eOverlaps
(
interval
)
{
function
merg
eOverlaps
(
interval
)
{
var
i
=
0
;
while
(
i
<
interval
.
length
-
1
)
{
var
endFirst
=
interval
[
i
][
1
];
var
startSecond
=
interval
[
i
+
1
][
0
];
var
endSecond
=
interval
[
i
+
1
][
1
];
if
(
endFirst
>
startSecond
)
{
if
(
endFirst
>
=
startSecond
)
{
interval
.
splice
(
i
+
1
,
1
);
interval
[
i
][
1
]
=
endSecond
;
}
...
...
@@ -227,10 +245,10 @@ function andNotOperator(interval1, interval2) {
return
andOperator
(
interval1
,
interval2
);
}
module
.
exports
.
standard
=
standard
;
module
.
exports
.
standardFromTillDay
=
standardFromTillDay
;
module
.
exports
.
cyclic
=
cyclic
;
module
.
exports
.
cyclicFromTillDay
=
cyclicFromTillDay
;
module
.
exports
.
orOperator
=
orOperator
;
module
.
exports
.
andOperator
=
andOperator
;
module
.
exports
.
andNotOperator
=
andNotOperator
;
module
.
exports
.
mergeOverlaps
=
mergeOverlaps
;
\ No newline at end of file
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