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
9b2e6653
Commit
9b2e6653
authored
Jul 10, 2014
by
Johannes Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added Mocha Test
parent
69a3e3d5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
23 deletions
+53
-23
dateArray.js
lib/dateArray.js
+6
-1
holidayMapping.json
lib/holidayMapping.json
+1
-1
holidays.js
lib/holidays.js
+46
-20
dateViewTest.js
test/dateViewTest.js
+0
-1
No files found.
lib/dateArray.js
View file @
9b2e6653
...
@@ -150,8 +150,13 @@ function wrapper(_epochSpan) {
...
@@ -150,8 +150,13 @@ function wrapper(_epochSpan) {
var
days
=
[];
var
days
=
[];
var
cnt
=
endYear
-
startYear
+
1
;
var
cnt
=
endYear
-
startYear
+
1
;
var
errRec
=
false
;
function
_cb
(
err
,
result
)
{
function
_cb
(
err
,
result
)
{
if
(
err
)
return
cb
(
err
);
if
(
errRec
)
return
;
if
(
err
){
errRec
=
true
;
return
cb
(
err
);
}
days
=
days
.
concat
(
result
);
days
=
days
.
concat
(
result
);
cnt
--
;
cnt
--
;
...
...
lib/holidayMapping.json
View file @
9b2e6653
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
"default"
:
[
"106"
,
"1"
,
"111"
]
"default"
:
[
"106"
,
"1"
,
"111"
]
},
},
"BY"
:
{
"BY"
:
{
"default"
:
[
"106"
,
"1"
,
"
815"
,
"
111"
],
"default"
:
[
"106"
,
"1"
,
"111"
],
"kath"
:
[
"815"
],
"kath"
:
[
"815"
],
"augsburg"
:
[
"808"
]
"augsburg"
:
[
"808"
]
},
},
...
...
lib/holidays.js
View file @
9b2e6653
...
@@ -26,19 +26,21 @@ var variableOffsets = {
...
@@ -26,19 +26,21 @@ var variableOffsets = {
602
:
50
602
:
50
};
};
var
holidayToSpecificMap
=
(
function
()
{
var
holidayToSpecificMap
=
(
function
()
{
var
regionH
=
holidayMapping
[
"region"
];
var
regionH
=
holidayMapping
[
"region"
];
var
hMap
=
{};
var
hMap
=
{};
for
(
var
rKey
in
regionH
)
{
for
(
var
rKey
in
regionH
)
{
var
rH
=
regionH
[
rKey
];
var
rH
=
regionH
[
rKey
];
for
(
var
cKey
in
rH
)
{
for
(
var
cKey
in
rH
)
{
var
hArray
=
rH
[
cKey
];
var
hArray
=
rH
[
cKey
];
for
(
var
i
=
0
;
i
<
hArray
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
hArray
.
length
;
i
++
)
{
var
hd
=
hArray
[
i
];
var
hd
=
hArray
[
i
];
if
(
!
hMap
[
hd
])
if
(
!
hMap
[
hd
])
hMap
[
hd
]
=
[];
hMap
[
hd
]
=
[];
if
(
cKey
==
"default"
)
hMap
[
hd
].
region
.
push
(
rKey
);
hMap
[
hd
].
push
({
else
hMap
[
hd
].
special
.
push
(
cKey
);
region
:
rKey
,
category
:
cKey
});
}
}
}
}
}
}
...
@@ -83,20 +85,20 @@ function Holidays(year) {
...
@@ -83,20 +85,20 @@ function Holidays(year) {
return
!!
(
86150
<=
plz
&&
plz
<=
86199
);
return
!!
(
86150
<=
plz
&&
plz
<=
86199
);
}
}
function
getRegionOptions
(
plz
,
epochSpan
,
cb
)
{
function
getRegionOptions
(
plz
,
keys
,
cb
)
{
var
blnd
;
var
blnd
;
var
options
=
{
var
options
=
{
isKath
:
false
,
isKath
:
false
,
isAugsburg
:
false
isAugsburg
:
false
};
};
restRequest
.
getBundesland
(
plz
,
function
(
err
,
result
)
{
restRequest
.
getBundesland
(
plz
,
function
(
err
,
result
)
{
if
(
err
)
return
cb
(
err
);
if
(
err
)
return
cb
(
err
);
blnd
=
result
;
blnd
=
result
;
options
.
blnd
=
blnd
;
options
.
blnd
=
blnd
;
if
(
blnd
==
"BY"
)
{
if
(
blnd
==
"BY"
)
{
options
.
isAugsburg
=
getIsAugsburg
(
plz
);
options
.
isAugsburg
=
getIsAugsburg
(
plz
);
restRequest
.
getKatholisch
(
plz
,
function
(
err1
,
isKath
)
{
restRequest
.
getKatholisch
(
plz
,
function
(
err1
,
isKath
)
{
if
(
err1
)
return
cb
(
err1
);
if
(
err1
)
return
cb
(
err1
);
options
.
isKath
=
isKath
;
options
.
isKath
=
isKath
;
cb
(
null
,
options
);
cb
(
null
,
options
);
})
})
...
@@ -107,22 +109,27 @@ function Holidays(year) {
...
@@ -107,22 +109,27 @@ function Holidays(year) {
});
});
}
}
function
isInEpochSpan
(
date
,
epochSpan
)
{
function
isInEpochSpan
(
date
,
epochSpan
)
{
var
dateTime
=
date
.
getTime
();
var
dateTime
=
date
.
getTime
();
return
epochSpan
[
0
].
getTime
()
<=
dateTime
&&
dateTime
<=
epochSpan
[
1
].
getTime
()
return
epochSpan
[
0
].
getTime
()
<=
dateTime
&&
dateTime
<=
epochSpan
[
1
].
getTime
()
}
}
function
getRelevantHolidayKeys
(
epochSpan
)
{
return
Object
.
keys
(
holidays
).
filter
(
function
(
key
)
{
return
isInEpochSpan
(
holidays
[
key
],
epochSpan
);
});
}
function
getHolidayKeys
(
plz
,
epochSpan
,
cb
)
{
function
getHolidayKeys
(
plz
,
epochSpan
,
cb
)
{
var
initKeys
=
getRelevantHolidayKeys
(
epochSpan
);
if
(
plz
==
0
)
{
if
(
plz
==
0
)
{
var
keys
=
Object
.
keys
(
holidays
);
return
cb
(
null
,
initKeys
);
return
cb
(
null
,
keys
);
}
}
getRegionOptions
(
plz
,
epochSpan
,
function
(
err
,
options
)
{
getRegionOptions
(
plz
,
initKeys
,
function
(
err
,
options
)
{
console
.
log
(
options
);
console
.
log
(
options
);
if
(
err
)
return
cb
(
err
);
if
(
err
)
return
cb
(
err
);
var
blnd
=
options
.
blnd
;
var
blnd
=
options
.
blnd
;
var
isAugsburg
=
options
.
isAugsburg
;
var
isAugsburg
=
options
.
isAugsburg
;
var
isKath
=
options
.
isKath
;
var
isKath
=
options
.
isKath
;
...
@@ -140,10 +147,27 @@ function Holidays(year) {
...
@@ -140,10 +147,27 @@ function Holidays(year) {
})
})
}
}
function
blndGetter
(
plz
)
{
var
blnd
;
var
errRec
;
function
getBlnd
(
cb
)
{
if
(
errRec
)
return
cb
(
errRec
);
if
(
blnd
)
return
cb
(
null
,
blnd
);
restRequest
.
getBundesland
(
plz
,
function
(
err
,
result
)
{
if
(
err
)
{
errRec
=
err
;
return
cb
(
err
);
}
cb
(
null
,
result
);
})
}
return
getBlnd
;
}
this
.
getAllHolidays
=
function
(
plz
,
epochSpan
,
cb
)
{
this
.
getAllHolidays
=
function
(
plz
,
epochSpan
,
cb
)
{
getHolidayKeys
(
plz
,
epochSpan
,
function
(
err
,
keys
)
{
getHolidayKeys
(
plz
,
epochSpan
,
function
(
err
,
keys
)
{
if
(
err
)
if
(
err
)
return
cb
(
err
);
return
cb
(
err
);
var
result
=
[];
var
result
=
[];
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
...
@@ -164,4 +188,6 @@ function Holidays(year) {
...
@@ -164,4 +188,6 @@ function Holidays(year) {
};
};
}
}
module
.
exports
=
Holidays
;
module
.
exports
=
Holidays
;
\ No newline at end of file
var
hds
=
new
Holidays
(
2014
);
test/dateViewTest.js
View file @
9b2e6653
...
@@ -7,7 +7,6 @@ var now = new Date(2014, 4, 1);
...
@@ -7,7 +7,6 @@ var now = new Date(2014, 4, 1);
dateArray
(
dateView
.
getPropperEpochSpan
(
now
)).
getData
(
require
(
'../mochaTests/testData/testHof.json'
),
0
,
function
(
err
,
data
)
{
dateArray
(
dateView
.
getPropperEpochSpan
(
now
)).
getData
(
require
(
'../mochaTests/testData/testHof.json'
),
0
,
function
(
err
,
data
)
{
console
.
log
(
data
);
var
view
=
dateView
.
getView
(
data
,
now
,
93047
);
var
view
=
dateView
.
getView
(
data
,
now
,
93047
);
fs
.
writeFile
(
process
.
env
[
"HOME"
]
+
'/Desktop/bla.html'
,
view
,
function
(
err
)
{
fs
.
writeFile
(
process
.
env
[
"HOME"
]
+
'/Desktop/bla.html'
,
view
,
function
(
err
)
{
...
...
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