1

Let's assume I have the following reminder timestamp

local reminder_timestamp = "2013-12-13T00:00:00+01:00"

And I'm using the below function to return time in UTC

local function makeTimeStamp(dateString)
      local pattern = "(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:([%d%.]+)([Z%p])(%d%d)%:?(%d%d)"
      local year, month, day, hour, minute, seconds, tzoffset, offsethour, offsetmin = dateString:match(pattern)
      local timestamp = os.time( {year=year, month=month, day=day, hour=hour, min=minute, sec=seconds} )
      local offset = 0
      if ( tzoffset ) then
        if ( tzoffset == "+" or tzoffset == "-" ) then  -- we have a timezone!
          offset = offsethour * 60 + offsetmin
          if ( tzoffset == "-" ) then
            offset = offset * -1
          end
          timestamp = timestamp + offset

        end
      end
  return timestamp
end

What should be the pattern above to match the reminder timestamp I mentioned earlier?

Mustafa
  • 140
  • 1
  • 9

2 Answers2

1

You need to use Lua's string parsing capabilities. Try a few of the techniques mentioned in the following, and if you still have issues, post specifically what is not working:

Community
  • 1
  • 1
Oliver
  • 27,510
  • 9
  • 72
  • 103
1

Here is the answer and the function actually works fine

pattern = "(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:([%d%.]+)([Z%p])(%d%d)%:?(%d%d)"

reminder_timestamp = "2013-12-23T08:00:00+01:00"

local year, month, day, hour, minute, seconds, tzoffset, offsethour, offsetmin = reminder_timestamp:match(pattern)

Resource: http://www.lua.org/manual/5.1/manual.html#5.4.1

Mustafa
  • 140
  • 1
  • 9