mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-18 23:52:52 +00:00
fix: add openingHours config and catch its errors
This commit is contained in:
1413
package-lock.json
generated
1413
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -89,7 +89,7 @@
|
||||
"ngx-logger": "4.1.9",
|
||||
"ngx-markdown": "9.1.1",
|
||||
"ngx-moment": "5.0.0",
|
||||
"opening_hours": "3.6.0",
|
||||
"opening_hours": "3.7.0",
|
||||
"rxjs": "6.6.3",
|
||||
"tslib": "1.14.1",
|
||||
"zone.js": "0.11.4"
|
||||
|
||||
@@ -20,7 +20,7 @@ import {Subscription} from 'rxjs';
|
||||
import {logger} from '../_helpers/ts-logger';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
|
||||
const openingHoursFn = require('opening_hours');
|
||||
const ohFunction = require('opening_hours');
|
||||
|
||||
@Injectable()
|
||||
@Pipe({
|
||||
@@ -96,7 +96,7 @@ export class StringSplitPipe implements PipeTransform {
|
||||
@Injectable()
|
||||
@Pipe({
|
||||
name: 'openingHours',
|
||||
pure: false,
|
||||
pure: true,
|
||||
})
|
||||
export class OpeningHoursPipe implements PipeTransform, OnDestroy {
|
||||
locale: string;
|
||||
@@ -140,10 +140,20 @@ export class OpeningHoursPipe implements PipeTransform, OnDestroy {
|
||||
|
||||
return;
|
||||
}
|
||||
const openingHours = new openingHoursFn(aString);
|
||||
let openingHours;
|
||||
|
||||
if ((openingHours.getWarnings() as string[]).length > 0) {
|
||||
logger.warn((openingHours.getWarnings() as string[]).join('. '));
|
||||
try {
|
||||
openingHours = new ohFunction(aString, {
|
||||
address: {
|
||||
country_code: 'de',
|
||||
state: 'Hessen',
|
||||
},
|
||||
lon: 8.667_97,
|
||||
lat: 50.129_16,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.warn(error);
|
||||
this.value = '';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user