Expressing a DATE as a number (system time) instead of a string?

I am tagging my FLAC files to use in JRiver Media Centre.
Several of their date tags like “Date (release)” expect a date number and not a string in the format of a date.
I believe their date number system uses the common system of counting days since the epoch date of 1st Jan 1900.
Is there a way expressing the dates stored in MusicBrainz in this number format or is it only available as strings?

There is currently no built-in scripting function to get the date as count of numbers.

If you know some programming this could be added as a plugin, implementing a custom scripting function. See Appendix A: Plugins API — MusicBrainz Picard v2.8.1 documentation

There is some date formatting with the $dateformat function. It uses format codes for Python’s strftime, see https://strftime.org/ . But I don’t think there is a code for the number of days since 1.1.1900

Try this plugin:

PLUGIN_NAME = "dayssince"
PLUGIN_AUTHOR = "Philipp Wolfer"
PLUGIN_DESCRIPTION = "Provides tagger script function $dayssince(date_to_parse, date_start=1900-01-01)."
PLUGIN_VERSION = '0.1'
PLUGIN_API_VERSIONS = ['2.0']
PLUGIN_LICENSE = "MIT"
PLUGIN_LICENSE_URL = "https://opensource.org/licenses/MIT"

import datetime
from picard.script import register_script_function
from picard.script.functions import _split_date

def dayssince(parser, date_to_parse, date_start="1900-01-01"):
    try:
        yr, mo, da = _split_date(date_to_parse)
        date_object = datetime.date(int(yr), int(mo), int(da))
        yr, mo, da = _split_date(date_start)
        start_object = datetime.date(int(yr), int(mo), int(da))
    except ValueError:
        return ''
    date_delta = date_object - start_object
    return str(date_delta.days)

register_script_function(dayssince)

Save this as a file with extension “.py” (e.g. dayssince.py) in your Picard’s plugin folder. Use it with a script like:

$set(Date \(release\),$dayssince(%date%))

You can also specify a different start date for the calculation, e.g.

$set(Date \(release\),$dayssince(%date%,1970-01-01))
3 Likes

Wow, thanks for the code.
That is above and beyond what I was expecting.
I will give it a go and let you know what happens

3 Likes

Hi outsidecontext

Thanks again, your Plugin works well with the caveat that it is two days out.
This is nothing to do with your code but upon investigation it appears there are a couple of oddities about this dating system.
Firstly the start date of 1900-01-01 is counted as day 1 not day 0.
Secondly apparently some systems count Feb 29 1900 as a day when in fact it was not a leap year due to the complex way those things are worked out.
So your code works perfectly, I just need to tweak it to account for the above.

Thanks for taking the time to do this for me.

2 Likes