File tree 1 file changed +5
-56
lines changed
1 file changed +5
-56
lines changed Original file line number Diff line number Diff line change
1
+ import { DurationFormat } from "@formatjs/intl-durationformat" ;
1
2
import type { HaDurationData } from "../../components/ha-duration-input" ;
2
3
import type { FrontendLocaleData } from "../../data/translation" ;
3
- import { formatListWithAnds } from "../string/format-list" ;
4
4
5
5
const leftPad = ( num : number ) => ( num < 10 ? `0${ num } ` : num ) ;
6
6
@@ -47,58 +47,7 @@ export const formatNumericDuration = (
47
47
export const formatDurationLong = (
48
48
locale : FrontendLocaleData ,
49
49
duration : HaDurationData
50
- ) => {
51
- const d = duration . days || 0 ;
52
- const h = duration . hours || 0 ;
53
- const m = duration . minutes || 0 ;
54
- const s = duration . seconds || 0 ;
55
- const ms = duration . milliseconds || 0 ;
56
-
57
- const parts : string [ ] = [ ] ;
58
- if ( d > 0 ) {
59
- parts . push (
60
- Intl . NumberFormat ( locale . language , {
61
- style : "unit" ,
62
- unit : "day" ,
63
- unitDisplay : "long" ,
64
- } ) . format ( d )
65
- ) ;
66
- }
67
- if ( h > 0 ) {
68
- parts . push (
69
- Intl . NumberFormat ( locale . language , {
70
- style : "unit" ,
71
- unit : "hour" ,
72
- unitDisplay : "long" ,
73
- } ) . format ( h )
74
- ) ;
75
- }
76
- if ( m > 0 ) {
77
- parts . push (
78
- Intl . NumberFormat ( locale . language , {
79
- style : "unit" ,
80
- unit : "minute" ,
81
- unitDisplay : "long" ,
82
- } ) . format ( m )
83
- ) ;
84
- }
85
- if ( s > 0 ) {
86
- parts . push (
87
- Intl . NumberFormat ( locale . language , {
88
- style : "unit" ,
89
- unit : "second" ,
90
- unitDisplay : "long" ,
91
- } ) . format ( s )
92
- ) ;
93
- }
94
- if ( ms > 0 ) {
95
- parts . push (
96
- Intl . NumberFormat ( locale . language , {
97
- style : "unit" ,
98
- unit : "millisecond" ,
99
- unitDisplay : "long" ,
100
- } ) . format ( ms )
101
- ) ;
102
- }
103
- return formatListWithAnds ( locale , parts ) ;
104
- } ;
50
+ ) =>
51
+ new DurationFormat ( locale . language , {
52
+ style : "long" ,
53
+ } ) . format ( duration ) ;
You can’t perform that action at this time.
0 commit comments