It is currently March 28th, 2024, 1:10 pm

lua time is interpreted in an odd way in this skin no 0 on AM hours = nope? [solved]

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

lua time is interpreted in an odd way in this skin no 0 on AM hours = nope? [solved]

Post by CodeCode »

Hello, I and some others are modifying the ical google calendar skin. They managed to get the time to mostly correctly display.

I have found that the 0's in the am hours and the difference between am and pm seem to be confused.

I have posted the skin for reference but the line looks like this:

Queue['Item'..i..'Time'] = Item.Date and os.date('%I:%M -', Item.Date) or ''

The %#I:%M crashes rainmeter... :oops:
Google Calendar ical_xx.xx.zip
(433.77 KiB) Downloaded 6 times
Last edited by CodeCode on October 18th, 2020, 11:48 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua time is interpreted in an odd way in this skin no 0 on AM hours = nope?

Post by balala »

CodeCode wrote: October 18th, 2020, 6:15 am I have found that the 0's in the am hours and the difference between am and pm seem to be confused.
It does work well for me. The times shown as 00:00 with the %H:%M format, is shown as 12:00 - AM if I switch to the %I:%M - %p format.
CodeCode wrote: October 18th, 2020, 6:15 am The %#I:%M crashes rainmeter... :oops:
Note that the # parameter is not valid in lua. It is in Rainmeter, however in lua it isn't, so you can't use it. That's why Rainmeter crashes...
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: lua time is interpreted in an odd way in this skin no 0 on AM hours = nope?

Post by jsmorley »

Correct. To duplicate the functionality of the # character in Lua, you would use string.gsub() to remove the leading 0:

Code: Select all

function Update()

someTime = string.gsub(os.date('%I:%M:%S', 1603005001),'^0','')
print(someTime)

end
string.gsub() can support two forms:

newString = string.gsub(oldString, regular expression search pattern, replacement)
newString = oldString:gsub(regular expression search pattern, replacement)

So this would also work, no real advantage either way, your preference... I kinda prefer this:

Code: Select all

function Update()

someTime = os.date('%I:%M:%S', 1603005001):gsub('^0','')
print(someTime)

end
http://lua-users.org/wiki/StringLibraryTutorial
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua time is interpreted in an odd way in this skin no 0 on AM hours = nope?

Post by balala »

jsmorley wrote: October 18th, 2020, 1:18 pm string.gsub() can support two forms:

newString = string.gsub(oldString, regular expression search pattern, replacement)
newString = oldString:gsub(regular expression search pattern, replacement)
As most (or hope I'm not wrong if I say all) functions in lua.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: lua time is interpreted in an odd way in this skin no 0 on AM hours = nope?

Post by jsmorley »

balala wrote: October 18th, 2020, 1:53 pm As most (or hope I'm not wrong if I say all) functions in lua.
Yes, as long as we are talking about a "method" in a "library". I mostly see / use it with the string, math and table libraries.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua time is interpreted in an odd way in this skin no 0 on AM hours = nope?

Post by balala »

jsmorley wrote: October 18th, 2020, 1:57 pm Yes, as long as we are talking about a "method" in a "library". I mostly see / use it with the string, math and table libraries.
Well, I don't know too much in lua, just what have I gathered while I was using it with Rainmeter, so it was just an observation, based on my experience.
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: lua time is interpreted in an odd way in this skin no 0 on AM hours = nope?

Post by CodeCode »

Ok, so sometimes the time is coming out 2 hours too early in the rainmeter skin from what is in my calendar. But not always.
jsmorley wrote: October 18th, 2020, 1:18 pm Correct. To duplicate the functionality of the # character in Lua, you would use string.gsub to remove the leading 0:

Code: Select all

function Update()

someTime = string.gsub(os.date('%I:%M:%S', 1603005001),'^0','')
print(someTime)

end
string.gsub() can support two forms:

newString = string.gsub(oldString, regular expression search pattern, replacement)
newString = oldString:gsub(regular expression search pattern, replacement)

So this would also work, no real advantage either way, your preference... I kinda prefer this:

Code: Select all

function Update()

someTime = os.date('%I:%M:%S', 1603005001):gsub('^0','')
print(someTime)

end
http://lua-users.org/wiki/StringLibraryTutorial
Where would that go in this line:

Code: Select all

Queue['Item'..i..'Time'] = Item.Date and os.date('%I:%M -', Item.Date) or ''
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: lua time is interpreted in an odd way in this skin no 0 on AM hours = nope?

Post by jsmorley »

CodeCode wrote: October 18th, 2020, 9:04 pm Where would that go in this line:

Code: Select all

Queue['Item'..i..'Time'] = Item.Date and os.date('%I:%M -', Item.Date) or ''
Queue['Item'..i..'Time'] = Item.Date and os.date('%I:%M -', Item.Date):gsub('^0','') or ''
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: lua time is interpreted in an odd way in this skin no 0 on AM hours = nope?

Post by CodeCode »

jsmorley wrote: October 18th, 2020, 9:30 pm Queue['Item'..i..'Time'] = Item.Date and os.date('%I:%M -', Item.Date):gsub('^0','') or ''
Thanks jsmorley, that fixed my issue as posted. :great:
Strange, I saw this solution somewhere else, and I tried it, but it did not work - however now it does... hmph. :?
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: lua time is interpreted in an odd way in this skin no 0 on AM hours = nope?

Post by CodeCode »

There remains the additional issue though.

Some of my calendar appointments are still coming out 2 hours earlier than they should.

The calendar even says 7 am - 8 am but is showing as 5am to 6 am. Even after deleting the event and re-entering it. O.O
Post Reply