It is currently April 20th, 2024, 4:26 am

Time measure cannot parse timezone

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Time measure cannot parse timezone

Post by balala »

mistic100 wrote: April 11th, 2019, 10:22 am (well, Europe is considering removing it anyway).
Well there are two years until then.
But the newest question is do you still need help?
mistic100
Posts: 35
Joined: October 12th, 2014, 5:27 pm

Re: Time measure cannot parse timezone

Post by mistic100 »

No its ok.

Here is my final solution using Lua script. It takes an ISO date in input with or without time offset (then it's assumed to be UTC) and outputs the time part in local time zone

Code: Select all

function Initialize() end

local function isnil(str)
    return str == nil or str == ''
end

function Update()
    -- get input
    local value = SELF:GetOption('Value')
    if isnil(value) then
        return ''
    end

    -- parse ISO date
    local Y, M, D, h, m, s, zh, zm = string.match(value, '(%d%d%d%d)-(%d%d)-(%d%d)T(%d%d):(%d%d):(%d%d)([+-]?%d?%d?):?(%d?%d?)')
    if isnil(Y) or isnil(M) or isnil(D) or isnil(h) or isnil(m) or isnil(s) then
        print('ToLocalTimeZone: Invalid input datetime ' .. value)
        return ''
    end

    -- get local time offset
    local ho, mo = string.match(os.date('%z'), '([+-]%d%d)(%d%d)')

    -- apply local offset
    h = tonumber(h) + tonumber(ho)
    m = tonumber(m) + tonumber(mo)

    -- apply input offset
    if not isnil(zh) then
        h = h - tonumber(zh)
    end
    if not isnil(zm) then
        m = m - tonumber(zm)
    end

    -- fix minutes outbounds
    if m >= 60 then
        h = h + 1
        m = m - 60
    elseif m < 0 then
        h = h - 1
        m = m + 60
    end

    -- fix hours outbounds
    if h >= 24 then
        h = h - 24
    elseif h < 0 then
        h = h + 24
    end

    -- format time
    return string.format('%02d:%02d', h, m)
end
Usage :

Code: Select all

[MeasureDateLocal]
Measure=Script
Scriptfile=#@#Scripts/ToLocalTimezone.lua
Value=[MeasureDateZoned]
DynamicVariables=1

[MeterTime]
Meter=String
Text=[MeasureDateLocal]
DynamicVariables=1
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Time measure cannot parse timezone

Post by balala »

mistic100 wrote: April 11th, 2019, 5:54 pm No its ok.

Here is my final solution using Lua script. It takes an ISO date in input with or without time offset (then it's assumed to be UTC) and outputs the time part in local time zone
Good, if you got it working through a lua script. Congratulations.