It is currently April 25th, 2024, 3:58 am

Time Stamp question

Discuss the use of Lua in Script measures.
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Time Stamp question

Post by balala »

Hello everybody,

There again is my turn to ask something.
I have an extremely simple lua code:
MyLua.lua:

Code: Select all

function Update()
	SKIN:Bang('!SetVariable', 'Time', os.time({day=27,month=09,year=2020,hour=1,min=0,sec=0}))
end
As you can see this file is returning the timestamp of the current day (09/27/2020 1:00 AM).
The above script file is used into a same way simple skin:

Code: Select all

[Rainmeter]
Update=1000

[MeasureLuaScriptSun]
Measure=SCRIPT
ScriptFile=#@#MyLua.lua

[MeasureTime]
Measure=Time
TimeStamp=2020-09-27 01:00:00
TimeStampFormat=%Y-%m-%d %H:%M:%S

[MeterValues]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=#Time##CRLF#[MeasureTime:TimeStamp]
DynamicVariables=1
The skin is returning the time stamp of the same date and time (09/27/2020 1:00 AM).
But the problem is that the two time stamps are extremely different. The time stamp returned by the Rainmeter code is around ten times greater then the time stamp returned by the lua script.
Question is how can I use the time stamp returned by a lua script file into a Time measure. Yes, I know I can use certain time format into the lua script file and return the time stamp this way, then use this into the TimeStamp option of a Time measure (along with a proper TimeStampFormat), but the question is why these time stamp values are so different and if there is a way to use the numeric (not formated) time stamp value directly into a TimeStamp option of a Time measure.

Thanks for any idea.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Time Stamp question

Post by jsmorley »

balala wrote: September 27th, 2020, 6:24 pm Hello everybody,

There again is my turn to ask something.
I have an extremely simple lua code:
MyLua.lua:

Code: Select all

function Update()
	SKIN:Bang('!SetVariable', 'Time', os.time({day=27,month=09,year=2020,hour=1,min=0,sec=0}))
end
As you can see this file is returning the timestamp of the current day (09/27/2020 1:00 AM).
The above script file is used into a same way simple skin:

Code: Select all

[Rainmeter]
Update=1000

[MeasureLuaScriptSun]
Measure=SCRIPT
ScriptFile=#@#MyLua.lua

[MeasureTime]
Measure=Time
TimeStamp=2020-09-27 01:00:00
TimeStampFormat=%Y-%m-%d %H:%M:%S

[MeterValues]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=#Time##CRLF#[MeasureTime:TimeStamp]
DynamicVariables=1
The skin is returning the time stamp of the same date and time (09/27/2020 1:00 AM).
But the problem is that the two time stamps are extremely different. The time stamp returned by the Rainmeter code is around ten times greater then the time stamp returned by the lua script.
Question is how can I use the time stamp returned by a lua script file into a Time measure. Yes, I know I can use certain time format into the lua script file and return the time stamp this way, then use this into the TimeStamp option of a Time measure (along with a proper TimeStampFormat), but the question is why these time stamp values are so different and if there is a way to use the numeric (not formated) time stamp value directly into a TimeStamp option of a Time measure.

Thanks for any idea.
Lua uses the Unix Epoch timestamp based on 1 January 1970, and Windows (and thus Rainmeter) uses a Windows FILETIME based on 1 January 1601. That is different by 11644473600 seconds. So you just need to add or subtract that many seconds to convert between them.

https://docs.rainmeter.net/snippets/convert-time/
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Time Stamp question

Post by balala »

jsmorley wrote: September 27th, 2020, 9:03 pm Lua uses the Unix Epoch timestamp based on 1 January 1970, and Windows (and thus Rainmeter) uses a Windows FILETIME based on 1 January 1601. That is different by 11644473600 seconds. So you just need to add or subtract that many seconds to convert between them.
Alright, got it. Thank you for the help. I should have to know, but didn't realize, even if myself have used this previously.
So thanks again.