Passed
Pull Request — master (#248)
by
unknown
04:57
created

server/src/Application/Common/MonthDate.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 30
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 25
mnd 0
bc 0
fnc 2
dl 0
loc 30
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10

2 Functions

Rating   Name   Duplication   Size   Complexity  
A MonthDate.getLastDay 0 7 1
A MonthDate.getFirstDay 0 12 1
1
import { lastDayOfMonth } from 'date-fns';
2
3
export class MonthDate {
4
    constructor(
5
        public readonly year: number,
6
        public readonly month: number
7
    ) {}
8
9
    getFirstDay(): Date {
10
        const date = new Date();
11
        date.setFullYear(this.year);
12
        date.setMonth(this.month - 1);
13
        date.setHours(0);
14
        date.setMinutes(0);
15
        date.setSeconds(0);
16
        date.setMilliseconds(0);
17
        date.setDate(1);
18
19
        return date;
20
    }
21
22
    getLastDay(): Date {
23
        const date = new Date();
24
        date.setFullYear(this.year);
25
        date.setMonth(this.month - 1);
26
27
        return lastDayOfMonth(date);
28
    }
29
}
30