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
3081c4d9
Commit
3081c4d9
authored
May 11, 2021
by
Johannes Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
quick fix for bodystreet with date-holidays
parent
1cf3c06f
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
1055 additions
and
242 deletions
+1055
-242
dateArray.js
lib/dateArray.js
+165
-157
holidays.js
lib/holidays.js
+104
-85
package-lock.json
package-lock.json
+785
-0
package.json
package.json
+1
-0
No files found.
lib/dateArray.js
View file @
3081c4d9
This diff is collapsed.
Click to expand it.
lib/holidays.js
View file @
3081c4d9
var
holidayMapping
=
require
(
'./holidayMapping.json'
);
const
holidayMapping
=
require
(
'./holidayMapping.json'
);
var
easterSunday
=
require
(
'./easterSunday'
);
const
easterSunday
=
require
(
'./easterSunday'
);
const
DateHolidays
=
require
(
'date-holidays'
);
var
requestHandler
=
require
(
'./regionInfoRequest'
);
let
requestHandler
=
require
(
'./regionInfoRequest'
);
var
easterSundays
=
{};
const
easterSundays
=
{};
var
fixedHolidays
=
{
const
fixedHolidays
=
{
101
:
"0101"
,
101
:
'0101'
,
106
:
"0601"
,
106
:
'0601'
,
501
:
"0105"
,
501
:
'0105'
,
808
:
"0808"
,
808
:
'0808'
,
815
:
"1508"
,
815
:
'1508'
,
103
:
"0310"
,
103
:
'0310'
,
131
:
"3110"
,
131
:
'3110'
,
111
:
"0111"
,
111
:
'0111'
,
121
:
"2412"
,
121
:
'2412'
,
122
:
"2512"
,
122
:
'2512'
,
123
:
"2612"
123
:
'2612'
};
};
var
variableOffsets
=
{
const
variableOffsets
=
{
301
:
-
2
,
301
:
-
2
,
302
:
0
,
302
:
0
,
303
:
1
,
303
:
1
,
...
@@ -29,48 +29,45 @@ var variableOffsets = {
...
@@ -29,48 +29,45 @@ var variableOffsets = {
603
:
60
603
:
60
};
};
function
Holidays
(
year
)
{
function
Holidays
(
year
)
{
function
getEasterSunday
()
{
function
getEasterSunday
()
{
if
(
!
easterSundays
[
year
])
if
(
!
easterSundays
[
year
])
{
easterSundays
[
year
]
=
easterSunday
.
getEasterSunday
(
year
);
easterSundays
[
year
]
=
easterSunday
.
getEasterSunday
(
year
);
}
return
easterSundays
[
year
];
return
easterSundays
[
year
];
}
}
function
getFixedHolidays
(
fixedHolidays
,
object
)
{
function
getFixedHolidays
(
fixedHolidays
,
object
)
{
var
result
=
object
||
{};
const
result
=
object
||
{};
for
(
var
key
in
fixedHolidays
)
{
for
(
const
key
in
fixedHolidays
)
{
var
dateString
=
fixedHolidays
[
key
];
const
dateString
=
fixedHolidays
[
key
];
var
date
=
parseInt
(
dateString
.
slice
(
0
,
2
));
const
date
=
parseInt
(
dateString
.
slice
(
0
,
2
));
var
month
=
parseInt
(
dateString
.
slice
(
2
,
4
));
const
month
=
parseInt
(
dateString
.
slice
(
2
,
4
));
result
[
key
]
=
new
Date
(
year
,
month
-
1
,
date
);
result
[
key
]
=
new
Date
(
year
,
month
-
1
,
date
);
}
}
return
result
;
return
result
;
}
}
function
getVariableHolidaysMap
(
offsets
,
object
)
{
function
getVariableHolidaysMap
(
offsets
,
object
)
{
var
result
=
object
||
{};
const
result
=
object
||
{};
var
easterDate
=
getEasterSunday
();
const
easterDate
=
getEasterSunday
();
for
(
var
key
in
offsets
)
{
for
(
const
key
in
offsets
)
{
var
offset
=
offsets
[
key
];
const
offset
=
offsets
[
key
];
result
[
key
]
=
new
Date
(
year
,
easterDate
.
getMonth
(),
easterDate
.
getDate
()
+
offset
);
result
[
key
]
=
new
Date
(
year
,
easterDate
.
getMonth
(),
easterDate
.
getDate
()
+
offset
);
}
}
return
result
;
return
result
;
}
}
var
holidays
=
getFixedHolidays
(
fixedHolidays
);
let
holidays
=
getFixedHolidays
(
fixedHolidays
);
holidays
=
getVariableHolidaysMap
(
variableOffsets
,
holidays
);
holidays
=
getVariableHolidaysMap
(
variableOffsets
,
holidays
);
function
getIsAugsburg
(
plz
)
{
function
getIsAugsburg
(
plz
)
{
return
!!
(
86150
<=
plz
&&
plz
<=
86199
);
return
!!
(
86150
<=
plz
&&
plz
<=
86199
);
}
}
function
isInEpochSpan
(
date
,
epochSpan
)
{
function
isInEpochSpan
(
date
,
epochSpan
)
{
var
dateTime
=
date
.
getTime
();
const
dateTime
=
date
.
getTime
();
return
epochSpan
[
0
].
getTime
()
<=
dateTime
&&
dateTime
<=
epochSpan
[
1
].
getTime
()
return
epochSpan
[
0
].
getTime
()
<=
dateTime
&&
dateTime
<=
epochSpan
[
1
].
getTime
()
;
}
}
function
getRelevantHolidayKeys
(
epochSpan
)
{
function
getRelevantHolidayKeys
(
epochSpan
)
{
...
@@ -80,9 +77,9 @@ function Holidays(year) {
...
@@ -80,9 +77,9 @@ function Holidays(year) {
}
}
function
getHolidayKeys
(
info
,
epochSpan
,
cb
)
{
function
getHolidayKeys
(
info
,
epochSpan
,
cb
)
{
var
initKeys
=
getRelevantHolidayKeys
(
epochSpan
);
const
initKeys
=
getRelevantHolidayKeys
(
epochSpan
);
var
specialKeys
=
holidayMapping
[
"specificHolidays"
].
filter
(
function
(
key
)
{
const
specialKeys
=
holidayMapping
[
'specificHolidays'
].
filter
(
function
(
key
)
{
return
initKeys
.
indexOf
(
key
)
>=
0
;
return
initKeys
.
indexOf
(
key
)
>=
0
;
});
});
...
@@ -91,50 +88,53 @@ function Holidays(year) {
...
@@ -91,50 +88,53 @@ function Holidays(year) {
}
}
requestHandler
.
getBundesland
(
info
,
function
(
err
,
blnd
)
{
requestHandler
.
getBundesland
(
info
,
function
(
err
,
blnd
)
{
if
(
err
)
return
cb
(
err
);
if
(
err
)
{
var
keys
=
holidayMapping
[
"sureHolidays"
].
filter
(
function
(
key
)
{
return
cb
(
err
);
}
const
keys
=
holidayMapping
[
'sureHolidays'
].
filter
(
function
(
key
)
{
return
initKeys
.
indexOf
(
key
)
>=
0
;
return
initKeys
.
indexOf
(
key
)
>=
0
;
});
});
var
regionMap
=
holidayMapping
[
"region"
][
blnd
];
const
regionMap
=
holidayMapping
[
'region'
][
blnd
];
if
(
regionMap
)
{
if
(
regionMap
)
{
var
regionHolidays
=
regionMap
[
'default'
];
const
regionHolidays
=
regionMap
[
'default'
];
for
(
var
i
=
0
;
i
<
regionHolidays
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
regionHolidays
.
length
;
i
++
)
{
var
key
=
regionHolidays
[
i
];
const
key
=
regionHolidays
[
i
];
if
(
initKeys
.
indexOf
(
key
)
>=
0
)
{
if
(
initKeys
.
indexOf
(
key
)
>=
0
)
{
keys
.
push
(
key
);
keys
.
push
(
key
);
}
}
}
}
}
else
{
console
.
error
(
new
Error
(
'No Mapping for Bundesland: '
+
blnd
));
}
}
else
{
if
(
blnd
!=
'BY'
)
{
console
.
error
(
new
Error
(
"No Mapping for Bundesland: "
+
blnd
));
}
if
(
blnd
!=
"BY"
)
{
cb
(
null
,
keys
);
cb
(
null
,
keys
);
}
}
else
{
else
{
if
(
regionMap
[
'augsburg'
]
&&
getIsAugsburg
(
info
.
zip
))
{
if
(
regionMap
[
"augsburg"
]
&&
getIsAugsburg
(
info
.
zip
))
{
const
augsHDs
=
regionMap
[
'augsburg'
];
var
augsHDs
=
regionMap
[
"augsburg"
];
for
(
let
i
=
0
;
i
<
augsHDs
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
augsHDs
.
length
;
i
++
)
{
const
key
=
augsHDs
[
i
];
var
key
=
augsHDs
[
i
];
if
(
initKeys
.
indexOf
(
key
)
>=
0
)
{
if
(
initKeys
.
indexOf
(
key
)
>=
0
)
keys
.
push
(
key
);
keys
.
push
(
key
);
}
}
}
}
}
if
(
regionMap
[
"kath"
]
&&
regionMap
[
"kath"
].
length
>
0
)
{
if
(
regionMap
[
'kath'
]
&&
regionMap
[
'kath'
].
length
>
0
)
{
requestHandler
.
getKatholisch
(
info
,
function
(
err
,
kath
)
{
requestHandler
.
getKatholisch
(
info
,
function
(
err
,
kath
)
{
if
(
err
)
return
cb
(
err
);
if
(
err
)
{
if
(
kath
)
{
return
cb
(
err
);
var
kathHDs
=
regionMap
[
"kath"
];
}
for
(
var
i
=
0
;
i
<
kathHDs
.
length
;
i
++
)
{
if
(
kath
)
{
var
key
=
kathHDs
[
i
];
const
kathHDs
=
regionMap
[
'kath'
];
if
(
initKeys
.
indexOf
(
key
)
>=
0
)
for
(
let
i
=
0
;
i
<
kathHDs
.
length
;
i
++
)
{
const
key
=
kathHDs
[
i
];
if
(
initKeys
.
indexOf
(
key
)
>=
0
)
{
keys
.
push
(
key
);
keys
.
push
(
key
);
}
}
}
}
}
cb
(
null
,
keys
);
cb
(
null
,
keys
);
})
});
}
}
else
{
else
{
cb
(
null
,
keys
);
cb
(
null
,
keys
);
}
}
}
}
...
@@ -142,30 +142,50 @@ function Holidays(year) {
...
@@ -142,30 +142,50 @@ function Holidays(year) {
}
}
this
.
getAllHolidays
=
function
(
info
,
epochSpan
,
cb
)
{
this
.
getAllHolidays
=
function
(
info
,
epochSpan
,
cb
)
{
if
(
info
.
countryCode
&&
[
'DE'
,
'GB'
,
'US'
].
includes
(
info
.
countryCode
))
{
const
dateHolidays
=
new
DateHolidays
(
info
.
countryCode
);
const
holidayDays
=
dateHolidays
.
getHolidays
(
2021
)
.
filter
(
x
=>
x
.
type
===
'public'
)
.
map
(
x
=>
{
const
dateDay
=
x
.
date
.
slice
(
0
,
10
);
// strip hours
const
date
=
new
Date
(
`
${
dateDay
}
T00:00`
);
// converts 2021-05-13 to "2021-05-12T22:00:00.000Z"
return
date
;
});
return
cb
(
null
,
holidayDays
);
}
getHolidayKeys
(
info
,
epochSpan
,
function
(
err
,
keys
)
{
getHolidayKeys
(
info
,
epochSpan
,
function
(
err
,
keys
)
{
if
(
err
)
if
(
err
)
{
return
cb
(
err
);
return
cb
(
err
);
var
result
=
[];
}
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
const
result
=
[];
var
key
=
keys
[
i
];
for
(
let
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
var
elem
=
holidays
[
key
];
const
key
=
keys
[
i
];
if
(
elem
)
const
elem
=
holidays
[
key
];
if
(
elem
)
{
result
.
push
(
elem
);
result
.
push
(
elem
);
}
}
}
cb
(
err
,
result
);
cb
(
err
,
result
);
});
});
};
};
this
.
getHoliday
=
function
(
id
)
{
this
.
getHoliday
=
function
(
id
)
{
if
(
id
==
0
)
{
if
(
id
==
0
)
{
var
ret
=
[];
const
ret
=
[];
for
(
var
key
in
holidays
)
for
(
const
key
in
holidays
)
{
ret
.
push
(
holidays
[
key
]);
ret
.
push
(
holidays
[
key
]);
}
return
ret
;
return
ret
;
}
}
if
(
id
in
holidays
)
if
(
id
in
holidays
)
{
return
[
holidays
[
id
]];
return
[
holidays
[
id
]];
console
.
error
(
"invalid holiday id "
+
id
);
}
console
.
error
(
'invalid holiday id '
+
id
);
return
null
;
return
null
;
};
};
}
}
...
@@ -177,20 +197,19 @@ module.exports = Holidays;
...
@@ -177,20 +197,19 @@ module.exports = Holidays;
* for testing reasons
* for testing reasons
* @param handler
* @param handler
*/
*/
module
.
exports
.
setRequestHandler
=
function
(
handler
)
{
module
.
exports
.
setRequestHandler
=
function
(
handler
)
{
requestHandler
=
handler
;
requestHandler
=
handler
;
};
};
module
.
exports
.
setTestHandler
=
function
()
{
module
.
exports
.
setTestHandler
=
function
()
{
requestHandler
=
{
requestHandler
=
{
getBundesland
:
function
(
plz
,
cb
)
{
getBundesland
:
function
(
plz
,
cb
)
{
// console.log("bundesland is bayern");
// console.log("bundesland is bayern");
cb
(
null
,
"BY"
);
cb
(
null
,
'BY'
);
},
},
getKatholisch
:
function
(
plz
,
cb
)
{
getKatholisch
:
function
(
plz
,
cb
)
{
// console.log("is katholic");
// console.log("is katholic");
cb
(
null
,
true
);
cb
(
null
,
true
);
}
}
};
};
};
};
package-lock.json
0 → 100644
View file @
3081c4d9
This diff is collapsed.
Click to expand it.
package.json
View file @
3081c4d9
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
"dependencies"
:
{
"dependencies"
:
{
"
async
"
:
"^2.0.1"
,
"
async
"
:
"^2.0.1"
,
"
bluebird
"
:
"^3.4.6"
,
"
bluebird
"
:
"^3.4.6"
,
"
date-holidays
"
:
"^3.3.0"
,
"
moment
"
:
"^2.15.0"
"
moment
"
:
"^2.15.0"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
...
...
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