@@ -34,50 +34,47 @@ export const sortByDate = <T>(a: T, b: T) =>
3434 moment ( a [ 'stop' ] ?? a ) . isBefore ( moment ( b [ 'stop' ] ?? b ) ) ? - 1 : 1 ;
3535
3636export class Time {
37+ public from : moment . Moment ;
38+ public to : moment . Moment ;
3739 private _moment : moment . Moment = moment ( ) ;
3840 private _format : string = 'YYYY-MM-DD' ;
39- constructor ( public month ?: number , public year ?: number ) {
40- if ( this . month !== undefined ) {
41- this . _moment . month ( this . month - 1 ) ;
41+
42+ constructor (
43+ private config : {
44+ month ?: number ;
45+ year ?: number ;
46+ from ?: string ;
47+ to ?: string ;
4248 }
43- if ( this . year !== undefined ) {
44- this . _moment . year ( this . year ) ;
49+ ) {
50+ if ( this . config . from && this . config . to ) {
51+ this . from = moment ( this . config . from ) ;
52+ this . to = moment ( this . config . to ) ;
53+ } else {
54+ if ( this . config . month !== undefined ) {
55+ this . _moment . month ( this . config . month - 1 ) ;
56+ }
57+ if ( this . config . year !== undefined ) {
58+ this . _moment . year ( this . config . year ) ;
59+ }
60+ this . from = this . _moment . clone ( ) . startOf ( 'month' ) ;
61+ this . to = this . _moment . clone ( ) . endOf ( 'month' ) ;
4562 }
4663 }
4764
48- get startOfMonth ( ) : moment . Moment {
49- return this . _moment . clone ( ) . startOf ( 'month' ) ;
50- }
51-
52- get endOfMonth ( ) : moment . Moment {
53- return this . _moment . clone ( ) . endOf ( 'month' ) ;
54- }
55-
56- get startOfMonthFormatted ( ) : string {
57- return this . startOfMonth . format ( this . _format ) ;
58- }
59-
60- get endOfMonthFormatted ( ) : string {
61- return this . endOfMonth . format ( this . _format ) ;
62- }
63-
64- get startOfMonthISO ( ) : string {
65- return this . startOfMonth . format ( ) ;
66- }
67-
68- get endOfMonthISO ( ) : string {
69- return this . endOfMonth . format ( ) ;
65+ get fromDateFormatted ( ) : string {
66+ return this . from . format ( this . _format ) ;
7067 }
7168
72- get startOfMonthEpoch ( ) : number {
73- return this . startOfMonth . valueOf ( ) ;
69+ get toDateFormatted ( ) : string {
70+ return this . to . format ( this . _format ) ;
7471 }
7572
76- get endOfMonthEpoch ( ) : number {
77- return this . endOfMonth . valueOf ( ) ;
73+ get fromAsISO ( ) : string {
74+ return this . from . format ( ) ;
7875 }
7976
80- get dueTimestamp ( ) : string {
81- return this . endOfMonth . utc ( ) . add ( 1 , 'day' ) . format ( ) ;
77+ get toAsISO ( ) : string {
78+ return this . to . format ( ) ;
8279 }
8380}
0 commit comments