Verbal Timestamps for fb2k

Last week I spent some time developing this algorithm in fb2k‘s titleformatting script to translate numerical timestamps (YYYY-MM-DD HH:MM:SS) into natural English text (“Friday Evening”).

verbal timestamps screenshot

It’s pretty cool. So, uh, here it is.

/////////////////////////////////////////
// NATURAL LANGUAGE TIMESTAMPS
// by topdownjimmy
// v0.4 - June 4, 2006
/////////////////////////////////////////

// calculate "dayssince": number of days since song was last played
$if(%last_played%,$puts(dayssince,$sub($add($mul($right(%_system_year%,2),365),$select(%_system_month%,0,31,59,90,120,151,181,212,243,273,304,334),$add($div($right(%_system_year%,2),4),$if($or($greater(%_system_month%,2),$greater($mod(%_system_year%,4),0)),1,0)),%_system_day%),$add($mul($substr(%last_played%,3,4),365),$select($substr(%last_played%,6,7),0,31,59,90,120,151,181,212,243,273,304,334),$add($div($substr(%last_played%,3,4),4),$if($or($greater($substr(%last_played%,6,7),2),$greater($mod($substr(%last_played%,1,4),4),0)),1,0)),$substr(%last_played%,9,10)))),$puts(dayssince,))

// correct "dayssince" to consider early AM to be an extension of previous day
$puts(dayssince,$sub($get(dayssince),$if($and($greater(7,%_system_hour%),$greater($substr(%last_played%,12,13),6)),1,0)))
$if($and($greater(%_system_hour%,6),$greater(7,$substr(%last_played%,12,13))),$puts(dayssince,$add($get(dayssince),1)),)

// calculate day of week
$puts(calcdayofweek,$add(1,$mod($add($substr(%last_played%,3,4),$div($substr(%last_played%,3,4),4),$select($substr(%last_played%,6,7),6,2,2,5,0,3,5,1,4,6,2,4),$substr(%last_played%,9,10)),7)))

// correct day of week to consider early AM to be an extension of previous day
$puts(calcdayofweek,$sub($get(calcdayofweek),$ifgreater(7,$substr(%last_played%,12,13),1,0)))
$if($strcmp($get(calcdayofweek),0),$puts(calcdayofweek,7),)

// calculate period of day (night, morning, etc.)
$puts(dayperiod,$select($add(1,$substr(%last_played% ,12,13)),Night,Night,Night,Night,Night,Night,Night,Morning,Morning,Morning,Morning,Morning,Afternoon
,Afternoon,Afternoon,Afternoon,Afternoon,Evening,Evening,Evening,Evening,Night,Night,Night))

// calculate natural language timestamp
$if(%last_played%,$puts(nat_lang_stamp,$ifgreater($get(dayssince),0,$ifgreater($get(dayssince),1,$ifgreater($get(dayssince),6,$if($and($greater($get(dayssince),21),$not($strcmp(%_system_month%,$substr(%last_played%,6,7)))),$if($not($strcmp(%_system_year%,$substr(%last_played%,1,4))),$select($substr(%last_played%,6,7),January,February,March,April,May,June,July,August,September,October,November,December)' '$substr(%last_played%,1,4),$ifgreater(2,$sub(%_system_month%,$substr(%last_played%,6,7)),'Last Month',$select($substr(%last_played%,6,7),January,February,March,April,May,June,July,August,September,October,November,December))),$ifgreater($div($add($get(dayssince),4),7),1,$div($add($get(dayssince),4),7)' Weeks Ago',Last Week)),$select($get(calcdayofweek),Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday)' '$get(dayperiod)),$if($strcmp($get(dayperiod),Night),Last,Yesterday)' '$get(dayperiod)),$if($strcmp($get(dayperiod),Night),Tonight,This $get(dayperiod)))),$puts(nat_lang_stamp,Never))

$set_global(nat_lang_stamp,$get(nat_lang_stamp))

/////////////////////////////////////////

Leave a Reply