Author Topic: Current date as seconds to columns?  (Read 2704 times)

laite

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Gmusicbrowser-plugins by laite
Current date as seconds to columns?
« on: March 14, 2011, 11:39:26 »
Hi. Would it be possible to have current date as seconds (since 1970-01-01 00:00:00 UTC) to use in columns? I'd like to format last_played as "X days/months/years ago" instead of playing date. I know I can get current date with %x but I couldn't figure out a way to use that to calculate time difference from last_played and get it to seconds, which is needed for formattime().

Quentin Sculo

  • Administrator
  • Hero Member
  • *****
  • Posts: 1082
    • View Profile
Re: Current date as seconds to columns?
« Reply #1 on: March 14, 2011, 21:43:11 »
I can easily add a function that returns the number of seconds since 1970, so I guess I can add it. Though I should add a better way to do that.
Also there is an option (in Misc. tab) that allows you to configure the default time format used based in the number of seconds from now. Though I'm not very happy with it, as it changes the display everywhere (not just in columns) and it doesn't work quite right with "Today" as I explain in this bug : https://github.com/squentin/gmusicbrowser/issues#issue/13

laite

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Gmusicbrowser-plugins by laite
Re: Current date as seconds to columns?
« Reply #2 on: March 14, 2011, 22:15:19 »
I can easily add a function that returns the number of seconds since 1970, so I guess I can add it. Though I should add a better way to do that.
Also there is an option (in Misc. tab) that allows you to configure the default time format used based in the number of seconds from now. Though I'm not very happy with it, as it changes the display everywhere (not just in columns) and it doesn't work quite right with "Today" as I explain in this bug : https://github.com/squentin/gmusicbrowser/issues#issue/13

Oh, somehow I have missed that option in 'misc'.

One option could be providing $today (or $now?) - field and functions for getting day/month/year/seconds out of it, so it could be used like: "full_seconds($today)-full_seconds($lastplay)" or perhaps "'Today's month is'.month($today)".
« Last Edit: March 15, 2011, 00:20:37 by laite »

laite

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Gmusicbrowser-plugins by laite
Re: Current date as seconds to columns?
« Reply #3 on: March 15, 2011, 10:14:14 »
Another idea for solution: hard-coded function daysago($lastplayed), which would return number of days as an integer. It would be possible to handle the "today/yesterday"-issue for example like this (I'm sorry, I can't code in perl) :
Code: [Select]
function daysago(lastplay)
{
  seconds_since_midnight = current_hour(24h mode)*3600+current_minute*60+current_second;
  # for example @ 9:30:06 seconds_since_midnight would be 9*3600+30*60+6=34206

  difference = (current_seconds_since_epoch_ - lastplay_) - seconds_since_midnight

  if (difference < 0) return 0;
  #played today

  else return (1 + floor(difference/(24*60*60)));
  #return the number of 'midnights' (rounded down)

}

Hope you get the idea.