@@ -5,10 +5,6 @@ import { get } from 'lodash-es';
5
5
6
6
import { enqueueScrobble } from 'store/actions/scrobbleActions' ;
7
7
8
- import format from 'date-fns/format' ;
9
- import isToday from 'date-fns/isToday' ;
10
- import getYear from 'date-fns/getYear' ;
11
-
12
8
import { Button , Input , Dropdown , DropdownToggle , DropdownMenu , DropdownItem , FormGroup , Label } from 'reactstrap' ;
13
9
import { useState } from 'react' ;
14
10
import { LazyLoadImage } from 'react-lazy-load-image-component' ;
@@ -31,6 +27,7 @@ import type { Scrobble } from 'utils/types/scrobble';
31
27
32
28
import './ScrobbleItem.css' ;
33
29
import { useSettings } from 'hooks/useSettings' ;
30
+ import { formatDuration , formatScrobbleTimestamp } from 'utils/datetime' ;
34
31
35
32
interface ScrobbleItemProps {
36
33
scrobble : Scrobble ;
@@ -110,8 +107,6 @@ export default function ScrobbleItem({
110
107
let songInfo ;
111
108
let songFullTitle ;
112
109
let statusIcon ;
113
- let theTimestamp ;
114
- let timestampFormat = '' ;
115
110
116
111
if ( noCover || compact ) {
117
112
albumArt = null ;
@@ -165,36 +160,15 @@ export default function ScrobbleItem({
165
160
}
166
161
}
167
162
168
- if ( scrobble . timestamp ) {
169
- const scrobbleDate = new Date ( scrobble . timestamp ) ;
170
- if ( ! isToday ( scrobbleDate ) ) {
171
- timestampFormat = settings ?. use12Hours ? 'M/d' : 'd/MM' ;
172
- if ( getYear ( scrobbleDate ) < getYear ( new Date ( ) ) ) {
173
- timestampFormat += '/yyyy' ;
174
- }
175
- timestampFormat += ' ' ;
176
- }
177
- timestampFormat += settings ?. use12Hours ? 'hh:mm a' : 'HH:mm' ;
178
- theTimestamp = format ( scrobbleDate , timestampFormat ) ;
179
- } else {
180
- if ( scrobble . duration > 0 ) {
181
- // Yes, there are songs over one hour. Is it worth making this more complex for those? (no, it isn't)
182
- const minutes = Math . floor ( scrobble . duration / 60 ) ;
183
- const seconds = `0${ scrobble . duration % 60 } ` . slice ( - 2 ) ;
184
- theTimestamp = `${ minutes } :${ seconds } ` ;
185
- } else {
186
- theTimestamp = '' ;
187
- }
188
- }
189
-
190
163
const timeOrDuration = (
191
164
< small
192
165
className = { `text-end timestamp d-flex align-items-center ${ compact ? 'flex-row' : 'flex-row-reverse' } ${
193
166
! scrobble . timestamp && 'duration text-muted'
194
167
} `}
195
168
>
196
169
{ scrobble . timestamp && < FontAwesomeIcon className = { `${ compact ? 'me-2' : 'ms-2' } ` } icon = { faClock } /> }
197
- { theTimestamp }
170
+ { scrobble . timestamp && formatScrobbleTimestamp ( scrobble . timestamp , settings ?. use12Hours ) }
171
+ { ! scrobble . timestamp && scrobble . duration > 0 && formatDuration ( scrobble . duration ) }
198
172
</ small >
199
173
) ;
200
174
0 commit comments