import moment from 'moment' ; import { IStorageWrapper } from 'src/plugins/opensearch_dashboards_utils/public' ; import { PersistedLog } from '../persisted_log' ; import { TimeRange } from '../../../common' ; export class TimeHistory { private history : PersistedLog < TimeRange > ; constructor ( storage ) { const historyOptions = { maxLength : 10 , filterDuplicates : true , isDuplicate : ( oldItem , newItem ) => { return oldItem . from === newItem . from && oldItem . to === newItem . to ; } , } ; this . history = new PersistedLog ( 'opensearchDashboards.timepicker.timeHistory' , historyOptions , storage ) ; } add ( time ) { if ( ! time || ! time . from || ! time . to ) { return ; } const justStringsTime = { from : moment . isMoment ( time . from ) ? time . from . toISOString ( ) : time . from , to : moment . isMoment ( time . to ) ? time . to . toISOString ( ) : time . to , } ; this . history . add ( justStringsTime ) ; } get ( ) { return this . history . get ( ) ; } } export type TimeHistoryContract = PublicMethodsOf < TimeHistory > ;