Skip to main content
Topic: Natural Language Timestamps (Read 22460 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Natural Language Timestamps

Here's some code I wrote to translate the %last_played% timestamp into natural, English descriptors, relative to the current date/time.



Note that you don't have to have had day-of-week stamping enabled; the script calculates the day of the week from the date.

The day period descriptors are customized to my lifestyle: 7am..MORNING..12pm..AFTERNOON..5pm..EVENING..9pm..NIGHT..7am

To change this simply change the $puts(dayperiod... ) line.  You'll also have to change the second line of code, the $puts(dayssince... ) modification that tells the script that 1am on Tuesday isn't TUESDAY...it's Monday.  To do this, change "$greater(%_system_hour%,7)" to whatever hour you define as the switch from night to morning.

Anyway it's probably still a little buggy, and not easily customizable, and the code isn't pretty, but I plan to continue to clean it up.  Please let me know if you notice any erratic behavior.

There are two versions.  The first is more up-to-date, and relies upon the cwb_hooks component.

Code: [Select]
/////////////////////////////////////////
// RELATIVE TIMESTAMPS
// formerly known as natural language timestamps
// by topdownjimmy - v0.5.c - May 6, 2007
/////////////////////////////////////////

// calculate days since last play
$puts(dayssince,$cwb_datediff(%cwb_systemdate%,%last_played%))

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

// calculate day of week of last play
$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 of last play (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(rel_timestamp,$ifgreater($get(dayssince),0,$ifgreater($get(dayssince),1,$ifgreater($get(dayssince),6,$if($and($greater($get(dayssince),21),$not($strcmp($left(%cwb_systemdate%,7),$left(%last_played%,7)))),$if($not($strcmp($left(%cwb_systemdate%,4),$substr(%last_played%,1,4))),$select($substr(%last_played%,6,7),January,February,March,April,May,June,July,August,September,October,November,December)' '$ifgreater($get(dayssince),334,$substr(%last_played%,1,4),),$ifgreater(2,$sub($substr(%cwb_systemdate%,6,7),$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(rel_timestamp,Never))

$set_global(rel_timestamp,$get(rel_timestamp))

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


The second version uses Columns UI's native date info, but hasn't been updated in a while.  Still does the trick though:

Code: [Select]
/////////////////////////////////////////
// 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))

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

In the first version, 0.5.c, the code to retrieve the relative timestamp is $get_global(rel_timestamp).

In the second, older version (0.4), the code is $get_global(nat_lang_stamp).

This remains a work in progress, so please discuss any problems you find in this thread.  Thanks.

Natural Language Timestamps

Reply #1
Great script. I've been wanting to do something like this. Btw, is your playlist font Tahoma? I thought it was, but I can't find the star symbol you are using for your ratings column in the character map. Would you mind sharing what font you are using and your code for the ratings column?

Natural Language Timestamps

Reply #2
Really nice  after "hotness", a new useful and "complex" script

I added it to my FAQ

Natural Language Timestamps

Reply #3
thanks that's cool  i'm testing 

edit:

@topdownjimmy: I just translated it to french for personnal use so i can share it if some french people are interested and if you agrees of course.

Sorry for the bad english, I'm french .

Natural Language Timestamps

Reply #4
fixed some bugs, updated code in first post.  still a little clunky but should be accurate now.

and of course, feel free to translate, i'm not really selfish about this

Natural Language Timestamps

Reply #5
Could you maybe add text for really recently played stuff like "5 minutes ago" or "2 hours ago?"

Still wondering about that font with the star glyph...

Natural Language Timestamps

Reply #6
another quick bugfix, 0.3...


Could you maybe add text for really recently played stuff like "5 minutes ago" or "2 hours ago?"

Still wondering about that font with the star glyph...

i'll see if i can get to that.  the font is "tahoma star," you can find it if you search for it in the forum.

Natural Language Timestamps

Reply #7
this is pretty cool.  Thanks, i'll give it a try.


Natural Language Timestamps

Reply #9
Great script. I've been wanting to do something like this. Btw, is your playlist font Tahoma? I thought it was, but I can't find the star symbol you are using for your ratings column in the character map. Would you mind sharing what font you are using and your code for the ratings column?


The star symbol can be entered by typing "hoshi" into the japanese IME in windows (hoshi being the japanese word for star).

Or you can cut/paste it from here --> ?

I suppose ideally it would be nice if someone could provide the $char() code for this character but I have not had much success figuring these out.

Natural Language Timestamps

Reply #10
$char(9733) and $char(9734) <- use charmap.exe
Maciek

Natural Language Timestamps

Reply #11
$char(9733) and $char(9734) <- use charmap.exe


At the risk of straying off-topic, would you please explain your process in a bit more detail? I am familiar with the character map utility and use it for many other things however I have been unsuccessful in obtaining the $char() code for any particular symbol for use in foobar.  Using charmap.exe, and also by referencing many of the unicode character tables found by googling, the numbers I come up with never seem to work properly.

In the case of this character for hoshi, when I use the character map tool I find the glyph in the table and the tool indicates that it is "Black Star U+2605".  Several different unicode tables also indicate this character table as 2605.  Would you please explain how 2605 becomes 9733 or am I doing something wrong to begin with? Is there perhaps some sort of offset that I am not taking into account? And of course $char(2605) does not display the star, it displays something else entirely.

Natural Language Timestamps

Reply #12
Use calc.exe

Those codes are given in hex, and need to be converted to decimal. Either do the conversion in your head (geek++) or start the calculator, switch the view to scientific, hit F5 to switch to Hex, enter 2605 and hit F6 to convert to decimal.

Natural Language Timestamps

Reply #13
aha! hex to binary.. that's the piece of the puzzle that has eluded me for so long. thank you very much

Natural Language Timestamps

Reply #14
Ok forgive the stupidity of this post, but how do you use this?

Is the code in the first post supposed to go in the globals tab and %_nat_lang_stamp% to go in the display tab?

Natural Language Timestamps

Reply #15
Ok forgive the stupidity of this post, but how do you use this?

Is the code in the first post supposed to go in the globals tab and %_nat_lang_stamp% to go in the display tab?

use $get_global(nat_lang_stamp), not %_nat_lang_stamp%. you'll also need to check all the boxes at the top of the globals tab except for the "legacy support" one.

Natural Language Timestamps

Reply #16

Ok forgive the stupidity of this post, but how do you use this?

Is the code in the first post supposed to go in the globals tab and %_nat_lang_stamp% to go in the display tab?

use $get_global(nat_lang_stamp), not %_nat_lang_stamp%. you'll also need to check all the boxes at the top of the globals tab except for the "legacy support" one.
Cool, thanks

Natural Language Timestamps

Reply #17
update, fixed "last week" bug

Natural Language Timestamps

Reply #18
Nice feture!Respect! I planned to do something like this myself,but i'm too lazy.Great work
Favourite artist:CD-R
Favourite album:700MB

Natural Language Timestamps

Reply #19
I tried to put it in the trackinfo panel, but it doesn't work right now.

Example:
I played a track yesterday evening and trackinfo showed that I played the track THIS evening.
(System time: 01:30pm)
Can anybody help me?




Cheers Lycox

Natural Language Timestamps

Reply #20
This works great.

Natural Language Timestamps

Reply #21
I tried to put it in the trackinfo panel, but it doesn't work right now.

Example:
I played a track yesterday evening and trackinfo showed that I played the track THIS evening.
(System time: 01:30pm)
Can anybody help me?




Cheers Lycox


I believe you cannot use this in trackinfo, only in columns_ui because trackinfo does not support "%_system_xxxx%... correct me if i'm worong...

Natural Language Timestamps

Reply #22
really nice!
thank you so much

Natural Language Timestamps

Reply #23
How would I go about modifying this to work with added info?

Would I just have to change every %last_played% to %added%?

Natural Language Timestamps

Reply #24
I think that should do it.

 
SimplePortal 1.0.0 RC1 © 2008-2019