Help - Search - Members - Calendar
Full Version: How much days passed...?
Hydrogenaudio Forums > Hosted Forums > foobar2000 > 3rd Party Plugins - (fb2k)
pasta
Hey!
How should look string in foobar 0.9 beta 13 in some of column in foo_ui_columns exhibitory how much days passed from last played track.
I know I must use foo_playcount but how?
Synthetic Soul
I can't test this, as I have no interest in putting Columns UI on, but this should work:

CODE
// extract parts from %last_played%, as per wiki suggestion
$puts(last_played_year,$substr(%last_played%,1,4))
$puts(last_played_month,$substr(%last_played%,6,7))
$puts(last_played_day,$substr(%last_played%,9,10))
$puts(last_played_hour,$substr(%last_played%,12,13))
$puts(last_played_min,$substr(%last_played%,15,16))
$puts(last_played_sec,$substr(%last_played%,18,19))

// find approximate number of days since 1970-01-01
$puts(system_totaldays,$add($mul($sub(%_system_year%,1970),365),
$select(%_system_month%,0,31,59,90,120,151,181,212,243,273,304,334),
%_system_day%))

// find approximate number of days difference between last_played and 1970-01-01
$puts(last_played_totaldays,$add($mul($sub($get(last_played_year),1970),365),
$select($get(last_played_month),0,31,59,90,120,151,181,212,243,273,304,334),
$get(last_played_day)))

// record the difference between both values in last_played_numdays
$puts(last_played_numdays,$sub($get(system_totaldays),$get(last_played_totaldays)))

// report last_played_numdays
$get(last_played_numdays)

The script does not understand leap years. It could, but it would be way more complex and I don't really think it's worth the extra overhead. The number of days passed since 1970-01-01 will definately be inaccurate, but the difference between today and %last_played% - the important bit - should only be fooled if there was a leap year in between you last playing the file and today... I think.

Edit: When I say "I can't test this", I have tested it; but I tested by setting system_totaldays manually. I just haven't tested with Columns UI, which provides the system date variables.

If anyone's interested, here's my test code:

CODE
$puts(system_year,2006)
$puts(system_month,2)
$puts(system_day,10)

$puts(system_totaldays,$add($mul($sub($get(system_year),1970),365),
$select($get(system_month),0,31,59,90,120,151,181,212,243,273,304,334),
$get(system_day)))
Synthetic Soul
I just couldn't let it lie...

I think this one is 100% accurate - including the calculation of number of days since 1997-01-01...

CODE
// extract parts from %last_played%, as per wiki suggestion
$puts(last_played_year,$substr(%last_played%,1,4))
$puts(last_played_month,$substr(%last_played%,6,7))
$puts(last_played_day,$substr(%last_played%,9,10))
$puts(last_played_hour,$substr(%last_played%,12,13))
$puts(last_played_min,$substr(%last_played%,15,16))
$puts(last_played_sec,$substr(%last_played%,18,19))

// find number of days since 1997-01-01
$puts(dy,$sub(%_system_year%,1997))
$puts(is_leap,$ifgreater($mod(%_system_year%,4),0,,1))
$puts(system_totaldays,$add($mul($get(dy),365),
$div($get(dy),4),
$select(%_system_month%,0,31,59,90,120,151,181,212,243,273,304,334),
$if($and($get(is_leap),$greater(%_system_month%,2)),1,0),
$sub(%_system_day%,1)))

// find number of days difference between last_played and 1997-01-01
$puts(dy,$sub($get(last_played_year),1997))
$puts(is_leap,$ifgreater($mod($get(last_played_year),4),0,,1))
$puts(last_played_totaldays,$add($mul($get(dy),365),
$div($get(dy),4),
$select($get(last_played_month),0,31,59,90,120,151,181,212,243,273,304,334),
$if($and($get(is_leap),$greater($get(last_played_month),2)),1,0),
$sub($get(last_played_day),1)))

// record the difference between both values in last_played_numdays
$puts(last_played_numdays,$sub($get(system_totaldays),$get(last_played_totaldays)))

// report last_played_numdays
$get(last_played_numdays)

I've tested this against VB's DateDiff() function and it all tallies.

Edit: And here's my test script:

CODE
$puts(system_year,2007)
$puts(system_month,11)
$puts(system_day,24)

// find approximate number of days since 1997-01-01
$puts(dy,$sub($get(system_year),1997))
$puts(is_leap,$ifgreater($mod($get(system_year),4),0,,1))
$puts(system_totaldays,$add($mul($get(dy),365),
$div($get(dy),4),
$select($get(system_month),0,31,59,90,120,151,181,212,243,273,304,334),
$if($and($get(is_leap),$greater($get(system_month),2)),1,0),
$sub($get(system_day),1)))

$get(system_totaldays)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.