Passed
Pull Request — master (#406)
by
unknown
06:20
created

server/src/Infrastructure/Common/Utils/dateUtils.ts   A

Complexity

Total Complexity 3
Complexity/F 0

Size

Lines of Code 28
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 21
mnd 3
bc 3
fnc 0
dl 0
loc 28
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import { format, parseISO } from 'date-fns';
2
3
export const minutesToHours = (value: number): string => {
4
  const hours = Math.floor(value / 60);
5
  const minutes = value % 60;
6
7
  if (hours === 0) {
8
    return `${value}m`;
9
  }
10
11
  if (minutes === 0) {
12
    return `${hours}h`;
13
  }
14
15
  return `${hours}h${minutes}`;
16
};
17
18
export const formatDate = (value: Date | string): string => {
19
  if (typeof value === 'string') {
20
    value = parseISO(value);
21
  }
22
  return format(value, 'dd/MM/yyyy');
23
};
24
25
export const formatHtmlDate = (value: Date): string => {
26
  return format(value, 'yyyy-MM-dd');
27
};
28