Comparing date/time?

Wonderful day!
 
I have to compare two different time stamps.
here is some pseudo code, that you know what I mean:

nowTime = ( os.date( "%c" ) ) write nowTime to sqlfile continueTime = nowtime +5h stop game progress if player want to continue set new nowtime, (nowTime = ( os.date( "%c" ) ) ) check if new nowtime is equal as continueTime OR later if yes continue game

Got it? I want to Compare two timestamps and when the time is reached, the game can continue.
I hope you know what I mean. How can I realise this in Lua / Corona?
Any Ideas?
 Much thanks!

  1. Why use SQL?   Better to just save this to a file as text or a JSON encoded table of field values.

  2. With basic Lua features and SSK this is easy: https://roaminggamer.github.io/RGDocs/pages/SSK2/

Here is a full example:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/04/dateTimeCompare.zip

( Note: I’m relaunching the simulator over and over in the video.  It isn’t running in a loop on its own. )

https://www.youtube.com/watch?v=NhDoc3Wzgrg&feature=youtu.be

-- ============================================================= -- ============================================================= io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) -- ============================================================= -- LOAD & INITIALIZE - SSK 2 -- ============================================================= require "ssk2.loadSSK" \_G.ssk.init( {} ) -- ============================================================= local minTimeBetweenRuns = 10 -- 10 seconds -- Standard Lua: -- https://docs.coronalabs.com/api/library/os/time.html local curTimeInSeconds = os.time(os.date( '\*t' )) -- SSK Extention of Lua Tables: -- https://roaminggamer.github.io/RGDocs/pages/SSK2/extensions/#saving-loading-tables local lastRun = table.load( "lastRun.json" ) -- returns 'nil' if file not found -- First Run if( lastRun == nil ) then display.newText( "First Run", centerX, centerY ) local lastRun = {} lastRun.ranAt = curTimeInSeconds lastRun.runs = 1 table.save( lastRun, "lastRun.json" ) -- Subsequent Run else local timeSinceLastRun = curTimeInSeconds - lastRun.ranAt display.newText( "Ran " .. tostring( lastRun.runs ) .. " times" , centerX, centerY ) display.newText( "Ran " .. tostring( timeSinceLastRun ) .. " seconds ago" , centerX, centerY + 50 ) if( timeSinceLastRun \< minTimeBetweenRuns ) then local tmp = display.newText( "Please wait " .. tostring( minTimeBetweenRuns - timeSinceLastRun ) .. " seconds" , centerX, centerY + 100 ) tmp:setFillColor(1,0,0) local tmp = display.newText( "Then restart the app." , centerX, centerY + 150 ) tmp:setFillColor(1,0,0) else local tmp = display.newText( "Welcome back!" , centerX, centerY + 100 ) tmp:setFillColor(0,1,0) lastRun.ranAt = curTimeInSeconds lastRun.runs = lastRun.runs + 1 table.save( lastRun, "lastRun.json" ) end end
  1. Why use SQL?   Better to just save this to a file as text or a JSON encoded table of field values.

  2. With basic Lua features and SSK this is easy: https://roaminggamer.github.io/RGDocs/pages/SSK2/

Here is a full example:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/04/dateTimeCompare.zip

( Note: I’m relaunching the simulator over and over in the video.  It isn’t running in a loop on its own. )

https://www.youtube.com/watch?v=NhDoc3Wzgrg&feature=youtu.be

-- ============================================================= -- ============================================================= io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) -- ============================================================= -- LOAD & INITIALIZE - SSK 2 -- ============================================================= require "ssk2.loadSSK" \_G.ssk.init( {} ) -- ============================================================= local minTimeBetweenRuns = 10 -- 10 seconds -- Standard Lua: -- https://docs.coronalabs.com/api/library/os/time.html local curTimeInSeconds = os.time(os.date( '\*t' )) -- SSK Extention of Lua Tables: -- https://roaminggamer.github.io/RGDocs/pages/SSK2/extensions/#saving-loading-tables local lastRun = table.load( "lastRun.json" ) -- returns 'nil' if file not found -- First Run if( lastRun == nil ) then display.newText( "First Run", centerX, centerY ) local lastRun = {} lastRun.ranAt = curTimeInSeconds lastRun.runs = 1 table.save( lastRun, "lastRun.json" ) -- Subsequent Run else local timeSinceLastRun = curTimeInSeconds - lastRun.ranAt display.newText( "Ran " .. tostring( lastRun.runs ) .. " times" , centerX, centerY ) display.newText( "Ran " .. tostring( timeSinceLastRun ) .. " seconds ago" , centerX, centerY + 50 ) if( timeSinceLastRun \< minTimeBetweenRuns ) then local tmp = display.newText( "Please wait " .. tostring( minTimeBetweenRuns - timeSinceLastRun ) .. " seconds" , centerX, centerY + 100 ) tmp:setFillColor(1,0,0) local tmp = display.newText( "Then restart the app." , centerX, centerY + 150 ) tmp:setFillColor(1,0,0) else local tmp = display.newText( "Welcome back!" , centerX, centerY + 100 ) tmp:setFillColor(0,1,0) lastRun.ranAt = curTimeInSeconds lastRun.runs = lastRun.runs + 1 table.save( lastRun, "lastRun.json" ) end end