Added a DurationString() method for a Song that returns time in format 04:05 or 15:04:05 if a song is one hour or more long.
This commit is contained in:
parent
010774d775
commit
f1e2eca876
@ -20,6 +20,13 @@ func (s *Song) ArtistTitle() string {
|
||||
return s.Artist + " - " + s.Title
|
||||
}
|
||||
|
||||
func (s *Song) DurationString() string {
|
||||
if s.Duration.Hours() > 0 {
|
||||
return time.UnixMilli(s.Duration.Milliseconds()).Format("15:04:05")
|
||||
}
|
||||
return time.UnixMilli(s.Duration.Milliseconds()).Format("04:05")
|
||||
}
|
||||
|
||||
func (s *Song) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(&struct {
|
||||
Artist string `json:"artist"`
|
||||
@ -32,7 +39,7 @@ func (s *Song) MarshalJSON() ([]byte, error) {
|
||||
Artist: s.Artist,
|
||||
Title: s.Title,
|
||||
DurationMill: s.Duration.Milliseconds(),
|
||||
Duration: time.UnixMilli(s.Duration.Milliseconds()).Format("04:05"),
|
||||
Duration: s.DurationString(),
|
||||
MaxListeners: s.MaxListeners,
|
||||
StartAt: s.StartAt.UTC().Format(time.RFC3339)})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user