import { DateTime , DATE_TIME_FORMATTER } from "model/time" ; import type { Todo } from "./markdown" ; import { ReminderFormatParameterKey , ReminderModel , TodoBasedReminderFormat } from "./reminder-base" ; class DefaultReminderModel implements ReminderModel { public static readonly regexp = /^(?<title1>.*?)\(@(?<time>.+?)\)(?<title2>.*)$/ ; static parse ( line , linkDatesToDailyNotes ? ) { if ( linkDatesToDailyNotes == null ) { linkDatesToDailyNotes = false ; } const result = DefaultReminderModel . regexp . exec ( line ) ; if ( result == null ) { return null ; } const title1 = result . groups ! [ 'title1' ] ! ; let time = result . groups ! [ 'time' ] ; if ( time == null ) { return null ; } const title2 = result . groups ! [ 'title2' ] ! ; if ( linkDatesToDailyNotes ) { time = time . replace ( "[[" , "" ) ; time = time . replace ( "]]" , "" ) ; } return new DefaultReminderModel ( linkDatesToDailyNotes , title1 , time , title2 ) ; } constructor ( private linkDatesToDailyNotes , public title1 , public time , public title2 ) { } getTitle ( ) { return `${ this . title1 . trim ( ) } ${ this . title2 . trim ( ) }` . trim ( ) ; } getTime ( ) { return DATE_TIME_FORMATTER . parse ( this . time ) ; } setTime ( time ) { this . time = DATE_TIME_FORMATTER . toString ( time ) ; } setRawTime ( rawTime ) { this . time = rawTime ; return true ; } toMarkdown ( ) { let result = `${ this . title1 }(@${ this . time })${ this . title2 }` ; if ( ! this . linkDatesToDailyNotes ) { return result ; } let time = DATE_TIME_FORMATTER . parse ( this . time ) ; if ( ! time ) { return result ; } const date = DATE_TIME_FORMATTER . toString ( time . clone ( false ) ) ; return result . replace ( date , `[[${ date }]]` ) ; } } export class DefaultReminderFormat extends TodoBasedReminderFormat < DefaultReminderModel > { public static readonly instance = new DefaultReminderFormat ( ) ; parseReminder ( todo ) { return DefaultReminderModel . parse ( todo . body , this . linkDatesToDailyNotes ( ) ) ; } newReminder ( title , time ) { return new DefaultReminderModel ( this . linkDatesToDailyNotes ( ) , title , time . toString ( ) , "" ) ; } private linkDatesToDailyNotes ( ) { return this . config . getParameter ( ReminderFormatParameterKey . linkDatesToDailyNotes ) ; } }