Date added property set to never after writing dateAdded

To discuss development of addons / skins / customization of MediaMonkey v5 / v2024

Moderators: jiri, drakinite, Addon Administrators

TIV73
Posts: 245
Joined: Sat Nov 12, 2011 1:31 pm

Date added property set to never after writing dateAdded

Post by TIV73 »

Hi,
I noticed that a bunch of my music files started to have no added date. A quick check revealed that it was related to a shorthand script I have been using to automatically update some track properties, which also included the dateAdded property.

What struck me as weird is that this script has been working fine for years, and only stopped working in the last few days. Due to the nature of the problem it's a bit hard to say exactly when the problem started, but the oldest other timestamp I could find was december 6th, which would neatly coincide with me installing version 2024.0.0.3082, which is also what I'm currently using.

Because of that I assumed that some API changed and I needed to update my script accordingly, but after checking the documentation at https://www.mediamonkey.com/docs/api/cl ... #dateAdded I couldn't find anything wrong with it, I was using it exactly as outlined in one of the examples.

It ultimately turned out to be the way I assigned the date property. I used `track.dateAdded = new Date()` which does not work, and sets the property to 0. Changing it to `app.utils.timestamp2DateTime( new Date().toISOString())` fixed it for me.

To verify this I wrote a short script to reproduce the behavior:

Code: Select all

    dateTest: async function() {
      let _this = this
  
      let trackList = await uitools.getSelectedTracklist()
      if (!trackList || trackList.count == 0) {
        return
      }
  
      let currDate = new Date()

      trackList.beginUpdate()
      trackList.locked(function() {
        for (let i = 0; i <= trackList.count - 1; i++) {
          let track = trackList.getValue(i)
          console.log(`Original track date - ${track.dateAdded}`)
          console.log(`New date - ${currDate}`)
          track.dateAdded = currDate // sets date added property to 0
          // track.dateAdded = app.utils.timestamp2DateTime( currDate.toISOString()) // works as expected
          console.log(`New track date - ${track.dateAdded}`)
        }
      })
  
      trackList.endUpdate()
      await trackList.commitAsync()
    }


If the script uses the `currDate.toISOString` line, I'm getting the following output:

Code: Select all

Original track date - 44350.86706517361
New date - Fri Dec 20 2024 16:49:54 GMT+0100 (Central European Standard Time)
New track date - 45646.65965277778

If it uses just the `currDate` line, the output looks like this:

Code: Select all

Original track date - 44226.01522314815
New date - Fri Dec 20 2024 16:57:18 GMT+0100 (Central European Standard Time)
New track date - 0

In the gui the track then looks like this:

Image
Not sure if that's an actual bug or just a typo in the documentation, but I figured I'd report it anyway.
Ludek
Posts: 5100
Joined: Fri Mar 09, 2007 9:00 am

Re: Date added property set to never after writing dateAdded

Post by Ludek »

Hi,
dateAdded has same type as the others TDateDime properties like trackModified, fileModified, lastTimePlayed
so yes, from JS code you need to use

Code: Select all

track.dateAdded = app.utils.timestamp2DateTime( new Date().toISOString());
and not just

Code: Select all

track.dateAdded = new Date();
I'll fix the docs, thanks!
Post Reply