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
252fa957
Commit
252fa957
authored
Jun 24, 2014
by
Johannes Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
operators finished
parent
ed95e60c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
17 deletions
+107
-17
app.js
app.js
+102
-15
test.js
test.js
+5
-2
No files found.
app.js
View file @
252fa957
//gibt zu betrachtenden Zeitraum an.
//gibt zu betrachtenden Zeitraum an.
var
_epochStart
=
new
Date
(
2014
,
5
,
24
,
0
);
var
_epochStart
=
new
Date
(
2014
,
5
,
24
,
0
);
var
_epochEnd
=
new
Date
(
_epochStart
.
getTime
()
+
30
*
24
*
3600
*
1000
);
var
_epochEnd
=
new
Date
(
_epochStart
.
getTime
()
+
100
*
24
*
3600000
);
console
.
log
(
"epochStart"
,
_epochStart
);
console
.
log
(
"epochEnd "
,
_epochEnd
);
function
_cyclicInterval
(
from
,
until
,
interval
,
epochStart
,
epochEnd
)
{
function
_cyclicInterval
(
from
,
until
,
interval
,
epochStart
,
epochEnd
)
{
if
(
from
>=
until
)
throw
new
Error
(
"startDate cant be greater than endDate"
);
if
(
from
>=
until
)
throw
new
Error
(
"startDate cant be greater than endDate"
);
...
@@ -22,8 +25,9 @@ function _cyclicInterval(from, until, interval, epochStart, epochEnd) {
...
@@ -22,8 +25,9 @@ function _cyclicInterval(from, until, interval, epochStart, epochEnd) {
* @param timeUntil.m
* @param timeUntil.m
* @param epochStart
* @param epochStart
* @param epochEnd
* @param epochEnd
* @param distanceDays
*/
*/
function
standard
(
day
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
)
{
function
standard
(
day
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
,
distanceDays
)
{
var
dayDiff
=
day
-
epochStart
.
getDay
();
var
dayDiff
=
day
-
epochStart
.
getDay
();
if
(
dayDiff
<
0
)
if
(
dayDiff
<
0
)
dayDiff
+=
7
;
dayDiff
+=
7
;
...
@@ -32,8 +36,9 @@ function standard(day, timeFrom, timeUntil, epochStart, epochEnd) {
...
@@ -32,8 +36,9 @@ function standard(day, timeFrom, timeUntil, epochStart, epochEnd) {
epochStart
.
getDate
()
+
dayDiff
,
timeFrom
.
h
,
timeFrom
.
m
);
epochStart
.
getDate
()
+
dayDiff
,
timeFrom
.
h
,
timeFrom
.
m
);
var
endDate
=
new
Date
(
epochStart
.
getFullYear
(),
epochStart
.
getMonth
(),
var
endDate
=
new
Date
(
epochStart
.
getFullYear
(),
epochStart
.
getMonth
(),
epochStart
.
getDate
()
+
dayDiff
,
timeUntil
.
h
,
timeUntil
.
m
);
epochStart
.
getDate
()
+
dayDiff
,
timeUntil
.
h
,
timeUntil
.
m
);
return
_cyclicInterval
(
startDate
,
endDate
,
7
*
24
*
3600000
,
epochStart
,
epochEnd
);
return
_cyclicInterval
(
startDate
,
endDate
,
distanceDays
*
24
*
3600000
,
epochStart
,
epochEnd
);
}
}
/**
/**
*
*
* @param dayFrom
* @param dayFrom
...
@@ -47,29 +52,111 @@ function standard(day, timeFrom, timeUntil, epochStart, epochEnd) {
...
@@ -47,29 +52,111 @@ function standard(day, timeFrom, timeUntil, epochStart, epochEnd) {
* @param epochStart {Date}
* @param epochStart {Date}
* @param epochEnd {Date}
* @param epochEnd {Date}
* @returns {Array}
* @returns {Array}
* @param distanceDays
*/
*/
function
standardFromTillDay
(
dayFrom
,
dayTill
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
)
{
function
standardFromTillDay
(
dayFrom
,
dayTill
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
,
distanceDays
)
{
var
result
=
[];
var
result
=
[];
for
(
var
i
=
dayFrom
;
i
<=
dayTill
;
i
++
)
{
for
(
var
i
=
dayFrom
;
i
<=
dayTill
;
i
++
)
{
result
=
result
.
concat
(
standard
(
i
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
))
result
=
result
.
concat
(
standard
(
i
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
,
distanceDays
))
}
}
result
=
sortDateIntervals
(
result
);
result
=
sortDateIntervals
(
result
);
return
result
;
return
result
;
}
}
function
cyclic
(
dayFrom
,
dayTill
,
noInMonth
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
)
{
function
cyclic
(
day
,
noInMonth
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
)
{
var
result
=
[];
epochStart
=
new
Date
(
epochStart
);
while
(
true
)
{
var
startDate
=
_getNextNoInMonthOccurence
(
day
,
epochStart
,
noInMonth
);
startDate
.
setHours
(
timeFrom
.
h
);
startDate
.
setMinutes
(
timeFrom
.
m
);
var
endDate
=
new
Date
(
startDate
);
endDate
.
setHours
(
timeUntil
.
h
);
endDate
.
setMinutes
(
timeUntil
.
m
);
if
(
endDate
>
epochEnd
)
break
;
else
{
result
.
push
([
startDate
,
endDate
]);
epochStart
=
new
Date
(
endDate
);
epochStart
.
setDate
(
epochStart
.
getDate
()
+
1
);
}
}
return
result
;
}
}
function
cyclicFromTillDay
(
dayFrom
,
dayTill
,
noInMonth
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
)
{
var
result
=
[];
epochStart
=
new
Date
(
epochStart
);
function
_getDateOccurenceInMonth
(
day
,
startDate
,
noInMonth
)
{
while
(
true
)
{
var
startDate
=
_getNextNoInMonthOccurence
(
dayFrom
,
epochStart
,
noInMonth
);
startDate
.
setHours
(
timeFrom
.
h
);
startDate
.
setMinutes
(
timeFrom
.
m
);
var
endDate
=
new
Date
(
startDate
);
endDate
.
setHours
(
timeUntil
.
h
);
endDate
.
setMinutes
(
timeUntil
.
m
);
if
(
endDate
>
epochEnd
)
break
;
else
{
result
.
push
([
startDate
,
endDate
]);
epochStart
=
new
Date
(
endDate
);
epochStart
.
setDate
(
epochStart
.
getDate
()
+
1
);
for
(
var
offset
=
1
;
offset
<=
dayTill
-
dayFrom
;
offset
++
)
{
startDate
=
new
Date
(
startDate
);
startDate
=
new
Date
(
startDate
);
var
dayDiff
=
day
-
startDate
.
getDay
()
+
7
;
endDate
=
new
Date
(
endDate
);
startDate
.
setDate
(
startDate
.
getDate
()
+
1
);
endDate
.
setDate
(
endDate
.
getDate
()
+
1
);
if
(
endDate
<=
epochEnd
)
result
.
push
([
startDate
,
endDate
]);
else
break
;
}
}
}
return
result
;
}
function
_cyclicFromTillDayOld
(
dayFrom
,
dayTill
,
noInMonth
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
)
{
var
firstDays
=
cyclic
(
dayFrom
,
noInMonth
,
timeFrom
,
timeUntil
,
epochStart
,
epochEnd
);
var
result
=
firstDays
.
slice
();
for
(
var
offset
=
1
;
offset
<=
dayTill
-
dayFrom
;
offset
++
)
{
for
(
var
i
=
0
;
i
<
firstDays
.
length
;
i
++
)
{
var
start
=
new
Date
(
firstDays
[
i
][
0
]);
var
end
=
new
Date
(
firstDays
[
i
][
1
]);
start
.
setDate
(
start
.
getDate
()
+
offset
);
end
.
setDate
(
end
.
getDate
()
+
offset
);
if
(
end
<=
epochEnd
)
result
.
push
([
start
,
end
]);
}
}
sortDateIntervals
(
result
);
return
result
;
}
function
_getNextNoInMonthOccurence
(
day
,
startDate
,
noInMonth
)
{
startDate
=
new
Date
(
startDate
);
var
_noInMonth
;
if
(
noInMonth
==
-
1
)
{
_noInMonth
=
1
;
startDate
.
setDate
(
startDate
.
getDate
()
+
7
);
}
else
{
_noInMonth
=
noInMonth
;
}
var
dayDiff
=
day
-
startDate
.
getDay
();
if
(
dayDiff
<
0
)
dayDiff
+=
7
;
startDate
.
setDate
(
startDate
.
getDate
()
+
dayDiff
);
startDate
.
setDate
(
startDate
.
getDate
()
+
dayDiff
);
var
currentNoInMonth
=
Math
.
floor
(
startDate
.
getDate
()
/
7
)
+
1
;
var
currentNoInMonth
=
Math
.
ceil
(
startDate
.
getDate
()
/
7
)
;
while
(
currentNoInMonth
!=
noInMonth
)
{
while
(
currentNoInMonth
!=
_
noInMonth
)
{
startDate
=
new
Date
(
startDate
.
getTime
()
+
7
*
24
*
3600000
);
startDate
=
new
Date
(
startDate
.
getTime
()
+
7
*
24
*
3600000
);
currentNoInMonth
=
Math
.
floor
(
startDate
.
getDate
()
/
7
)
+
1
;
currentNoInMonth
=
Math
.
ceil
(
startDate
.
getDate
()
/
7
);
}
if
(
noInMonth
==
-
1
)
{
startDate
.
setDate
(
startDate
.
getDate
()
-
7
);
}
}
return
startDate
;
return
startDate
;
}
}
...
@@ -172,8 +259,8 @@ function andNotOperator(interval1, interval2) {
...
@@ -172,8 +259,8 @@ function andNotOperator(interval1, interval2) {
//var y = andNotOperator(a, c);
//var y = andNotOperator(a, c);
//console.log(y);
//console.log(y);
//var workday = standardFromTillDay(1, 5, {h: 9, m: 0}, {h: 11, m: 45}, _epochStart, _epochEnd
);
var
workday
=
standardFromTillDay
(
1
,
2
,
{
h
:
9
,
m
:
0
},
{
h
:
11
,
m
:
45
},
_epochStart
,
_epochEnd
,
14
);
//
console.log(workday);
console
.
log
(
workday
);
var
x
=
_getDateOccurenceInMonth
(
1
,
new
Date
(),
5
);
//var t = cyclicFromTillDay(1, 7, -1, {h: 9, m: 0}, {h: 18, m: 29}, _epochStart, _epochEnd);
console
.
log
(
x
);
//console.log(t);
\ No newline at end of file
\ No newline at end of file
test.js
View file @
252fa957
var
x
=
new
Date
();
var
x
=
new
Date
();
var
y
=
new
Date
(
x
);
y
.
setDate
(
1
);
console
.
log
(
x
);
console
.
log
(
x
);
x
.
setDate
(
-
1
);
console
.
log
(
y
);
console
.
log
(
x
);
\ No newline at end of file
\ 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