mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-28 03:46:06 -05:00 
			
		
		
		
	Make date suggestions timezone-unaware
This commit is contained in:
		| @@ -1,8 +1,8 @@ | |||||||
| import { Component, forwardRef, Input, OnInit } from '@angular/core' | import { Component, forwardRef, Input, OnInit } from '@angular/core' | ||||||
| import { NG_VALUE_ACCESSOR } from '@angular/forms' | import { NG_VALUE_ACCESSOR } from '@angular/forms' | ||||||
| import { | import { | ||||||
|  |   NgbDateAdapter, | ||||||
|   NgbDateParserFormatter, |   NgbDateParserFormatter, | ||||||
|   NgbDateStruct, |  | ||||||
| } from '@ng-bootstrap/ng-bootstrap' | } from '@ng-bootstrap/ng-bootstrap' | ||||||
| import { SettingsService } from 'src/app/services/settings.service' | import { SettingsService } from 'src/app/services/settings.service' | ||||||
| import { AbstractInputComponent } from '../abstract-input' | import { AbstractInputComponent } from '../abstract-input' | ||||||
| @@ -25,36 +25,31 @@ export class DateComponent | |||||||
| { | { | ||||||
|   constructor( |   constructor( | ||||||
|     private settings: SettingsService, |     private settings: SettingsService, | ||||||
|     private ngbDateParserFormatter: NgbDateParserFormatter |     private ngbDateParserFormatter: NgbDateParserFormatter, | ||||||
|  |     private isoDateAdapter: NgbDateAdapter<string> | ||||||
|   ) { |   ) { | ||||||
|     super() |     super() | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Input() |   @Input() | ||||||
|   suggestions: Date[] |   suggestions: string[] | ||||||
|  |  | ||||||
|   getSuggestions() { |   getSuggestions() { | ||||||
|     if (this.suggestions == null) return [] |     return this.suggestions == null | ||||||
|  |       ? [] | ||||||
|     return this.suggestions |       : this.suggestions | ||||||
|       .map((s) => new Date(s)) // required to call the date functions below |           .map((s) => this.ngbDateParserFormatter.parse(s)) | ||||||
|       .filter( |           .filter( | ||||||
|         (d) => |             (d) => | ||||||
|           this.value === null || // if value is not set, take all suggestions |               this.value === null || // if value is not set, take all suggestions | ||||||
|           d.toISOString().slice(0, 10) != this.value // otherwise filter out the current value |               this.value != this.isoDateAdapter.toModel(d) // otherwise filter out current date | ||||||
|       ) |           ) | ||||||
|       .map((s) => |           .map((s) => this.ngbDateParserFormatter.format(s)) | ||||||
|         this.ngbDateParserFormatter.format({ |  | ||||||
|           year: s.getFullYear(), |  | ||||||
|           month: s.getMonth() + 1, // month of Date is zero based |  | ||||||
|           day: s.getDate(), |  | ||||||
|         }) |  | ||||||
|       ) |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   onSuggestionClick(dateString: string) { |   onSuggestionClick(dateString: string) { | ||||||
|     const parsedDate = this.ngbDateParserFormatter.parse(dateString) |     const parsedDate = this.ngbDateParserFormatter.parse(dateString) | ||||||
|     this.writeValue(`${parsedDate.year}-${parsedDate.month}-${parsedDate.day}`) |     this.writeValue(this.isoDateAdapter.toModel(parsedDate)) | ||||||
|     this.onChange(this.value) |     this.onChange(this.value) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,5 +7,5 @@ export interface PaperlessDocumentSuggestions { | |||||||
|  |  | ||||||
|   storage_paths?: number[] |   storage_paths?: number[] | ||||||
|  |  | ||||||
|   dates?: Date[] |   dates?: string[] // ISO-formatted date string e.g. 2022-11-03 | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon