mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
Replacing local date format with ISO string format as Date.parse only supports that reliably cross browser. #312
This commit is contained in:
parent
d9a91a824f
commit
37594f1b88
@ -60,13 +60,13 @@ export class SearchQueryParser {
|
||||
return text;
|
||||
}
|
||||
|
||||
private static stringifyDate(time: number): string {
|
||||
public static stringifyDate(time: number): string {
|
||||
const date = new Date(time);
|
||||
// simplify date with yeah only if its first of jan
|
||||
if (date.getMonth() === 0 && date.getDate() === 1) {
|
||||
return date.getFullYear().toString();
|
||||
}
|
||||
return this.stringifyText(date.toLocaleDateString());
|
||||
return this.stringifyText(date.toISOString().substring(0, 10));
|
||||
}
|
||||
|
||||
private static parseDate(text: string): number {
|
||||
@ -82,7 +82,12 @@ export class SearchQueryParser {
|
||||
d.setFullYear(parseInt(text, 10));
|
||||
return d.getTime();
|
||||
}
|
||||
return Date.parse(text);
|
||||
const timestamp = Date.parse(text);
|
||||
if (isNaN(timestamp)) {
|
||||
throw new Error('Cannot parse date: ' + text);
|
||||
}
|
||||
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public parse(str: string, implicitAND = true): SearchQueryDTO {
|
||||
@ -257,7 +262,7 @@ export class SearchQueryParser {
|
||||
if (str.charAt(typeTmp.key.length) === '"' && str.charAt(str.length - 1) === '"') {
|
||||
ret.text = str.slice(typeTmp.key.length + 1, str.length - 1);
|
||||
ret.matchType = TextSearchQueryMatchTypes.exact_match;
|
||||
// like match
|
||||
// like match
|
||||
} else if (str.charAt(typeTmp.key.length) === '(' && str.charAt(str.length - 1) === ')') {
|
||||
ret.text = str.slice(typeTmp.key.length + 1, str.length - 1);
|
||||
} else {
|
||||
|
@ -38,12 +38,12 @@ export class AutoCompleteService {
|
||||
this.keywords.push(this.searchQueryParserService.keywords.to + ':' +
|
||||
SearchQueryParser.stringifyText((new Date()).getFullYear().toString()));
|
||||
this.keywords.push(this.searchQueryParserService.keywords.to + ':' +
|
||||
SearchQueryParser.stringifyText((new Date()).toLocaleDateString()));
|
||||
SearchQueryParser.stringifyText(SearchQueryParser.stringifyDate(Date.now())));
|
||||
|
||||
this.keywords.push(this.searchQueryParserService.keywords.from + ':' +
|
||||
SearchQueryParser.stringifyText((new Date()).getFullYear().toString()));
|
||||
this.keywords.push(this.searchQueryParserService.keywords.from + ':' +
|
||||
SearchQueryParser.stringifyText((new Date()).toLocaleDateString()));
|
||||
SearchQueryParser.stringifyText(SearchQueryParser.stringifyDate(Date.now())));
|
||||
|
||||
TextSearchQueryTypes.forEach(t => {
|
||||
this.textSearchKeywordsMap[(this.searchQueryParserService.keywords as any)[SearchQueryTypes[t]]] = t;
|
||||
|
Loading…
x
Reference in New Issue
Block a user