It is currently January 30th, 2023, 6:20 pm

Formatted Uptime skin

Clocks and timer skins
User avatar
jsmorley
Developer
Posts: 22558
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Formatted Uptime skin

Post by jsmorley »

I kinda thought the Uptime formatting today is a bit geeky, and figured it would be nice to have a variant that allows for "Restarted on / at" instead of "Up for".
8-23-2012 12-15-06 PM.png
UpTimeF_1.3.rmskin
The output can be formatted using the same codes from Measure=Time.
You do not have the required permissions to view the files attached to this post.
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: Formatted Uptime skin

Post by KreAch3R »

When I clicked to download the skin, I was thinking "boy, he must have done very complicated stuff to match the format from the Time measure to the os.date function". I was amazed to find out that both work with the same formatting codes.

This, to me, is one more proof of how professionally Rainmeter is developed. Well done to everyone.

Going back on topic, another great lua example Jeff. Getting script options, parsing them, making the user decide the output and returning it through the measure, in a few lines of code. Consider commenting it and adding it in the Lua tutorials. :)
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
jsmorley
Developer
Posts: 22558
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Formatted Uptime skin

Post by jsmorley »

Thanks,

There are two little "gotchas" I deal with in the Lua. The first is that Measure=Time uses a "#" format option in the string to remove leading zeros. That is not supported in the standard C strftime function used by Lua. So I have to play a little trick where I switch "%#" to "#%" so I can allow the user to format the string with the Measure=Time codes and not have Lua/Rainmeter blow up. Then I can use the # char to find and remove leading zeros.

The second is that the "%" char in Lua is a "magic escape" that to use as a literal must be escaped with itself, thus the sFormat = string.gsub(SELF:GetOption('Format'), '%%#', '#%%') construct when I "switch" the # and % chars.

Other than that, it is all pretty simple and straightforward.
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: Formatted Uptime skin

Post by KreAch3R »

I had noticed the replacements, but I didn't understand they played such a big role. It is a genious little trick.
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
jsmorley
Developer
Posts: 22558
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Formatted Uptime skin

Post by jsmorley »

Skin in first post vastly simplified thanks to Smurfier remembering that Measure=Time returns a number of elapsed seconds in the "number" value by default...
Alex Becherer

Re: Formatted Uptime skin

Post by Alex Becherer »

that's pretty cool.
it would be even nicer in a webparser skin. so a news item could display "five minutes ago" instead of the actual publish time.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Formatted Uptime skin

Post by Kaelri »

Alex Becherer wrote:that's pretty cool.
it would be even nicer in a webparser skin. so a news item could display "five minutes ago" instead of the actual publish time.
Working on it. :)
User avatar
jsmorley
Developer
Posts: 22558
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Formatted Uptime skin

Post by jsmorley »

Alex Becherer wrote:that's pretty cool.
it would be even nicer in a webparser skin. so a news item could display "five minutes ago" instead of the actual publish time.
Actually not that hard, I have several skins that do that now. Difficult to make it "generic" for any feed though. The problem is that there are just tons of ways that <Pubdate> or whatever you use can be formatted, and taking daylight savings time into consideration can be a tad complicated.

So unless you want to have a HUGE function to try to "figure out" date formats and timezones, you need to get the date format of the feed and customize a bit.

Here is an example of one that works nice:
RainGit_1.0.rmskin
You do not have the required permissions to view the files attached to this post.