It is currently April 26th, 2024, 6:14 pm

[solved] Using Uptime Format to Calculate the date (eg 'days ago') the pc was restarted on.

Get help with creating, editing & fixing problems with skins
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

[solved] Using Uptime Format to Calculate the date (eg 'days ago') the pc was restarted on.

Post by CodeCode »

So, the way I have been using the formatting for my uptime skin is like this:

Code: Select all

[MeasureUPTIME]
Measure=uptime
Format=%4!02i!:%3!02i!:%2!02i!:%1!02i!
So I am not sure how to grind everything into seconds to reconstitute it to a grand total of days (or partial days if <24 hours ago).
The measure would actually hinge on the date rather than the time - but that wouldn't be horrible if that was resolved as a part of this idea.

I am asking mostly because I do not understand the time formatting - that was essentially borrowed from another thread some time ago..

Thanks for any help getting this to make sense in code.
Last edited by CodeCode on August 22nd, 2021, 1:45 pm, edited 1 time in total.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Using Uptime Format to Calculate the date (eg 'days ago') the pc was restarted on.

Post by CodeCode »

Ok, a bit more was certainly descriptive here. But I am still in the dark on calculating back to the restart time, the new idea is to be able to capture the last time the pc was started - so that the 'hynrid' FULL shutdown is always used, then the time the pc has been up is exactly the last reboot, essentially. This is actually all new to me, and the manual explains it - but I don't understand it.

So, thanks for any help with this idea.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using Uptime Format to Calculate the date (eg 'days ago') the pc was restarted on.

Post by jsmorley »

CodeCode wrote: August 19th, 2021, 3:54 pm Ok, a bit more was certainly descriptive here. But I am still in the dark on calculating back to the restart time, the new idea is to be able to capture the last time the pc was started - so that the 'hynrid' FULL shutdown is always used, then the time the pc has been up is exactly the last reboot, essentially. This is actually all new to me, and the manual explains it - but I don't understand it.

So, thanks for any help with this idea.

Code: Select all

[MeasureGetUserName]
Measure=Plugin
Plugin=SysInfo
SysInfoType=USER_NAME
UpdateDivider=-1

[MeasureCurrentTime]
Measure=Time

[MeasureUserLoginTime]
Measure=Plugin
Plugin=SysInfo
SysInfoType=USER_LOGONTIME
UpdateDivider=-1

[MeasureFormatSeconds]
Measure=UpTime
SecondsValue=([MeasureCurrentTime:] - [MeasureUserLoginTime:])
Format="%4!i!d %3!i!h %2!i!m"
UpdateDivider=2
DynamicVariables=1

[MeasureUpTime]
Measure=UpTime
Format="%4!i!d %3!i!h %2!i!m"
UpdateDivider=2
This will measure both the "system" uptime, which will reflect either a FULL shutdown or a restart - and a "user" uptime, which will reflect either a HYBRID shutdown or any logoff / logon of the account.

This uses the SysInfo plugin to get the value for the "user" time in seconds, and then Uptime measures to format the seconds into day/hours/minutes/seconds as desired.

Looks like this in my skin. The times are more or less the same, as the last thing I did was a "restart", which will reset both.

1.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Using Uptime Format to Calculate the date (eg 'days ago') the pc was restarted on.

Post by CodeCode »

Ya, thats cool. But I came up with these calcs:

Code: Select all

[MeasureDayStarted]
Measure=Uptime
Format=%4!02i!
DynamicVariables=1

[MeasureDateNumber]
Measure=Time
Format=%d
DynamicVariables=1

[MeasureStartDayCalc]
Measure=Calc
Formula=(((([MeasureDateNumber:] / 60) / 60) /24) - ((([MeasureDayStarted:] / 60) / 60) /24))
DynamicVariables=1

[MeasureOkMan]
Measure=Calc
Formula=(MeasureDateNumber + MeasureStartDayCalc)
DynamicVariables=1

[MeterText]
Meter=String
MeasureName=MeasureOkMan
Text=%1
Which gives me (here in Aus) a value of 17, which means the 17th of August. Which Is what I was trying for - sort of date restarted as per calendar modality.
It may be really kludgy. So if a simpler method is there, I'd be happy to use that instead.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Using Uptime Format to Calculate the date (eg 'days ago') the pc was restarted on.

Post by CodeCode »

I also need to say thanks for the descriptive use of the SysInfoType=USER_LOGONTIME.

Cheers :thumbup:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using Uptime Format to Calculate the date (eg 'days ago') the pc was restarted on.

Post by jsmorley »

I'm not sure I follow the end-result you are looking for, but something like this will change the system uptime into a calendar date:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureNow]
Measure=Time

[MeasureDayStarted]
Measure=Uptime

[MeasureDateStarted]
Measure=Time
TimeStamp=([MeasureNow:TimeStamp]-[MeasureDayStarted:])
Format=%A, %B %#d, %Y %#I:%M %p
DynamicVariables=1

[MeterDate]
Meter=String
MeasureName=MeasureDateStarted
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1


1.jpg


If you only want the "day of the month" that this happened on, just use

Format=%#d

In the Time measure. I personally don't care for this idea, as I think the day of the month without any context of the month involved might be pretty weird and confusing at the beginning of a month, but again, I'm not sure I follow what your end-result is.
You do not have the required permissions to view the files attached to this post.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Using Uptime Format to Calculate the date (eg 'days ago') the pc was restarted on.

Post by CodeCode »

Oh man. That is exactly what I was going for! I can go from there I think. I always come up with more to ask about though. :lol:

Thanks J! :rosegift:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using Uptime Format to Calculate the date (eg 'days ago') the pc was restarted on.

Post by jsmorley »

CodeCode wrote: August 19th, 2021, 4:27 pm Oh man. That is exactly what I was going for! I can go from there I think. I always come up with more to ask about though. :lol:

Thanks J! :rosegift:
Glad to help.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using Uptime Format to Calculate the date (eg 'days ago') the pc was restarted on.

Post by jsmorley »

For this instance of displaying the values as a "date" rather than "elapsed time", the approach is similar, but slightly different with Uptime and USER_LOGONTIME.

Uptime by default is a number of seconds that have elapsed since a full restart of the computer, so you need to subtract that from "now" in order to get full date/time Timestamp value to use in the Time measure to it convert to a "date".

USER_LOGONTIME is already a full date / time Timestamp value, so you don't need any subtraction. Just use the Time measure to convert it to a "date".

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureDayStarted]
Measure=Plugin
Plugin=SysInfo
SysInfoType=USER_LOGONTIME
UpdateDivider=-1

[MeasureDateStarted]
Measure=Time
TimeStamp=[MeasureDayStarted:]
Format=%A, %B %#d, %Y %#I:%M %p
UpdateDivider=-1
DynamicVariables=1

[MeterDate]
Meter=String
MeasureName=MeasureDateStarted
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
This is because Windows treats Uptime as "how long ago?" (seconds) and treats USER_LOGONTIME as "when?" (timestamp).

Note that I use UpdateDivider=-1 with the values for USER_LOGONTIME, as it's value that can't possibly change while your system is running. With Uptime, we don't do that, as the number of elapsed seconds since a restart is constantly changing.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Using Uptime Format to Calculate the date (eg 'days ago') the pc was restarted on.

Post by CodeCode »

jsmorley wrote: August 19th, 2021, 4:38 pm For this instance of displaying the values as a "date" rather than "elapsed time", the approach is similar, but slightly different with Uptime and USER_LOGONTIME.

Uptime by default is a number of seconds that have elapsed since a full restart of the computer, so you need to subtract that from "now" in order to get full date/time Timestamp value to use in the Time measure to it convert to a "date".

USER_LOGONTIME is already a full date / time Timestamp value, so you don't need any subtraction. Just use the Time measure to convert it to a "date".

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureDayStarted]
Measure=Plugin
Plugin=SysInfo
SysInfoType=USER_LOGONTIME
UpdateDivider=-1

[MeasureDateStarted]
Measure=Time
TimeStamp=[MeasureDayStarted:]
Format=%A, %B %#d, %Y %#I:%M %p
UpdateDivider=-1
DynamicVariables=1

[MeterDate]
Meter=String
MeasureName=MeasureDateStarted
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
This is because Windows treats Uptime as "how long ago?" (seconds) and treats USER_LOGONTIME as "when?" (timestamp).
Oh yeah! That is much better.
I also added seconds, and with this:

Code: Select all

[MeasureDateStarted]
Measure=Time
TimeStamp=([MeasureNow:TimeStamp]-[MeasureDayStarted:])
Format=%h %#d#CRLF#%H:%M:%S
DynamicVariables=1
I was getting a see-saw between two seconds values changing every 10 seconds. And in the end the value was actually wrong, according to the more absolute version above.
Awesome apples!
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.