TimeStamp error from Corona Tutorial?

So I’m rolling with Rob Miracle’s tutorial on IAP. Specifically, I’ve used the timestamp code. And most of the time it works fine. But if I attempt to use on a Google Play device, I get an error that “field ‘day’ cannot be found” on all transactions/restores.

[lua]-- event.transaction.date shows as:

“Sat Mar 15 22:57:04 GMT+08:00 2014”[/lua]

Here’s the command being passed to timestamp:

[lua]local timeStamp = shop.makeTimeStamp(event.transaction.date, “ctime”)

if timeStamp + 360 < os.time() then 

      state = “restored”

      restoring = false

end

[/lua]

And here’s the timestamp code I used. Rob, one of the comments had the exact same bug, and you said you updated the tutorial, but…not for this? (Hard to tell, I just can’t read any of the string pattern)

[lua]function shop.makeTimeStamp(dateString, mode)

    local pattern = “(%d+)%-(%d+)%-(%d+)%a(%d+)% :(%d+)% :([%d%.]+)([Z%p])(%d*)%:?(%d*)”;

    local xyear, xmonth, xday, xhour, xminute, xseconds, xoffset, xoffsethour, xoffsetmin

    local monthLookup = {Jan = 1, Feb = 2, Mar = 3, Apr = 4, May = 5, Jun = 6, Jul = 7, Aug = 8, Sep = 9, Oct = 10, Nov = 11, Dec = 12}

    local convertedTimestamp

    local offset = 0

    if mode and mode == “ctime” then

        pattern = “%w+%s+(%w+)%s+(%d+)%s+(%d+)% :(%d+)% :(%d+)%s+(%w+)%s+(%d+)”

        local monthName, TZName

        monthName, xday, xhour, xminute, xseconds, TZName, xyear = string.match(dateString,pattern)

        xmonth = monthLookup[monthName]

        convertedTimestamp = os.time({year = xyear, month = xmonth,

        day = xday, hour = xhour, min = xminute, sec = xseconds})

    else

        xyear, xmonth, xday, xhour, xminute, xseconds, xoffset, xoffsethour, xoffsetmin = string.match(dateString,pattern)

        convertedTimestamp = os.time({year = xyear, month = xmonth,

        day = xday, hour = xhour, min = xminute, sec = xseconds})

        if xoffsetHour then

            offset = xoffsethour * 60 + xoffsetmin

            if xoffset == “-” then

                offset = offset * -1

            end

        end

    end

    return convertedTimestamp + offset

end[/lua]

The spaces in there I don’t think should be there.  That date string is a “ctime” date string, so when you call makeTimeStamp, pass “ctime” as the 2nd parameter.  You do still need to take those spaces out.

pattern = “%w+%s+(%w+)%s+(%d+)%s+(%d+)%:(%d+)%:(%d+)%s+(%w+)%s+(%d+)”

There’s no spaces in the string; that appears to be a forum formatting thing because its trying to convert the bits following. It’s a direct copy/paste from the tutorial.

Likewise, I cant read what you posted because of the smiley conversion. :frowning:

Its just the string you had taking the spaces out.  No other differences

Here, let me paste again

pattern = "%w+%s+(%w+)%s+(%d+)%s+(%d+)%:(%d+)%:(%d+)%s+(%w+)%s+(%d+)"

That’s the exact line in my code for “ctime” that’s getting the error.

pattern = "(%w+)%s+(%w+)%s+(%d+)%s+(%d+)%:(%d+)%:(%d+)%s+(%w+[%+%-]%d+%:%d+)%s+(%d+)"

Try that. 

No luck…

(first line is just a print statement, but I get the rest upon boot up through store.restore() or via any purchase thereafter. (Galaxy Note 3)

Using ctime

I/Corona  (16088): xday    Mar    xhour    16    xminute    02    xseconds    48

I/Corona  (16088): Runtime error

I/Corona  (16088): field ‘day’ missing in date table

I/Corona  (16088): stack traceback:

I/Corona  (16088):     [C]: ?

I/Corona  (16088):     [C]: in function ‘time’

I/Corona  (16088):     ?: in function ‘makeTimeStamp’

I/Corona  (16088):     ?: in function <?:81>

I/Corona  (16088): Runtime error

I/Corona  (16088): 

I/Corona  (16088): stack traceback:

I/Corona  (16088):     [C]: ?

I/Corona  (16088):     [C]: in function ‘time’

I/Corona  (16088):     ?: in function ‘makeTimeStamp’

I/Corona  (16088):     ?: in function <?:81>

Here is the code I used to test it:

pattern = "(%w+)%s+(%w+)%s+(%d+)%s+(%d+)%:(%d+)%:(%d+)%s+(%w+[%+%-]%d+%:%d+)%s+(%d+)" dateString = "Sat Mar 15 22:57:04 GMT+08:00 2014" dayName, monthName, xday, xhour, xminute, xseconds, TZName, xyear = string.match(dateString,pattern) print(dayName, monthName, xday, xhour, xminute, xseconds, TZName, xyear)

This is what was output:

Sat    Mar    15    22    57    04    GMT+08:00    2014

I would print out each individual value and see whats not getting passed to os.time() correctly.  I suspect its something to do with the month name to month number look up.

That fixed it; the missing element was to start off with ‘dayName’.  So to anyone else reading…

  1. Swap out the pattern entry in the article for the one Rob has above

  2. Pre-declare ‘dayName’

  3. Make sure ‘dayName’ is the first variable listed on the string.match() line.

None of those 3 changes are in the tutorial so you’ll need to make the changes yourself.

Thanks Rob - this was literally the last bug. I can push to stores tomorrow morning. :slight_smile:

The spaces in there I don’t think should be there.  That date string is a “ctime” date string, so when you call makeTimeStamp, pass “ctime” as the 2nd parameter.  You do still need to take those spaces out.

pattern = “%w+%s+(%w+)%s+(%d+)%s+(%d+)%:(%d+)%:(%d+)%s+(%w+)%s+(%d+)”

There’s no spaces in the string; that appears to be a forum formatting thing because its trying to convert the bits following. It’s a direct copy/paste from the tutorial.

Likewise, I cant read what you posted because of the smiley conversion. :frowning:

Its just the string you had taking the spaces out.  No other differences

Here, let me paste again

pattern = "%w+%s+(%w+)%s+(%d+)%s+(%d+)%:(%d+)%:(%d+)%s+(%w+)%s+(%d+)"

That’s the exact line in my code for “ctime” that’s getting the error.

pattern = "(%w+)%s+(%w+)%s+(%d+)%s+(%d+)%:(%d+)%:(%d+)%s+(%w+[%+%-]%d+%:%d+)%s+(%d+)"

Try that. 

No luck…

(first line is just a print statement, but I get the rest upon boot up through store.restore() or via any purchase thereafter. (Galaxy Note 3)

Using ctime

I/Corona  (16088): xday    Mar    xhour    16    xminute    02    xseconds    48

I/Corona  (16088): Runtime error

I/Corona  (16088): field ‘day’ missing in date table

I/Corona  (16088): stack traceback:

I/Corona  (16088):     [C]: ?

I/Corona  (16088):     [C]: in function ‘time’

I/Corona  (16088):     ?: in function ‘makeTimeStamp’

I/Corona  (16088):     ?: in function <?:81>

I/Corona  (16088): Runtime error

I/Corona  (16088): 

I/Corona  (16088): stack traceback:

I/Corona  (16088):     [C]: ?

I/Corona  (16088):     [C]: in function ‘time’

I/Corona  (16088):     ?: in function ‘makeTimeStamp’

I/Corona  (16088):     ?: in function <?:81>

Here is the code I used to test it:

pattern = "(%w+)%s+(%w+)%s+(%d+)%s+(%d+)%:(%d+)%:(%d+)%s+(%w+[%+%-]%d+%:%d+)%s+(%d+)" dateString = "Sat Mar 15 22:57:04 GMT+08:00 2014" dayName, monthName, xday, xhour, xminute, xseconds, TZName, xyear = string.match(dateString,pattern) print(dayName, monthName, xday, xhour, xminute, xseconds, TZName, xyear)

This is what was output:

Sat    Mar    15    22    57    04    GMT+08:00    2014

I would print out each individual value and see whats not getting passed to os.time() correctly.  I suspect its something to do with the month name to month number look up.

That fixed it; the missing element was to start off with ‘dayName’.  So to anyone else reading…

  1. Swap out the pattern entry in the article for the one Rob has above

  2. Pre-declare ‘dayName’

  3. Make sure ‘dayName’ is the first variable listed on the string.match() line.

None of those 3 changes are in the tutorial so you’ll need to make the changes yourself.

Thanks Rob - this was literally the last bug. I can push to stores tomorrow morning. :slight_smile: