Normal time works, date table does not? Android...

Hey everyone, 

Its probably going to be a bit hard for me to describe my problem so I’ll do my best. I’m trying to adjust os.date() using the following method…

local t = os.date("!\*t", os.time() \* 20.57142857142857)

Which to my understanding gets a Coordinated Universal Time? I’m displaying this time using a timer as show below…

 myText = display.newText( "", 100, 200, native.systemFont, 12 ) myText:setFillColor( 1, 0, 0.5 ) myText.text = "Time: " .. t.hour .. " : " .. t.min .. " : " .. t.sec timer.performWithDelay( 1000, listener, 0)

Now the above code works perfectly…on the simulator…but not on my Android device? When I run the application on my device, the timer doesn’t run? However, if I displayed the time using this method…

local nt = os.date("\*t", os.time())

The device runs the code perfectly? So it seems to a problem with using the Coordinated Universal Time and a text field? 

The device I am testing on is a Samsung Galaxy S4, running Android 4.4.2

Additional Information: 

I ran aLogCat to try and determine what the error was, the only problem that seems to be appearing when the application is running is 

D/AbsListView(18230) unregisterIRListener() is called

The above error keeps showing up when my application is running. Hope someone can help with this :slight_smile: I’ve been trying for 3 - 4 hours researching the cause / solution but with no luck :( 

Hi @1991.danielnelson,

You may want to read the following tutorial on working with dates/times:

http://coronalabs.com/blog/2013/01/15/working-with-time-and-dates-in-corona/

Best regards,

Brent

Hi Brent, 

I’ve looked through that tutorial a few times before and have tried most if not all of the methods it contains with no success. I have managed to find different ways of calculating the time I need, but whenever it goes on the device, it doesn’t work. 

It seems to only happen when os.time() is multiplied. I tried os.time() +20.57142857142857) which worked fine on the device, its only when the os.time() is multiplied will it not work. 

I also tried adding the permission android.permission.SET_TIME but discovered that its not possible for an application to request that permission :/ 

What are you trying to do?

Can you post your code that’s not working?

Hi Rob,

local t = os.date("!\*t", os.time() \* 20.57142857142857)

 myText = display.newText( "", 100, 200, native.systemFont, 12 ) myText:setFillColor( 1, 0, 0.5 ) myText.text = "Time: " .. t.hour .. " : " .. t.min .. " : " .. t.sec timer.performWithDelay( 1000, listener, 0)

The above code, does work in the simulator, but not on my Android device. I’m basically trying to find out why it does not work on my phone :slight_smile:

Basically what I need to do is to display the current time of a game that I play. The way I work it out like this: os.date("!*t", os.time() * 20.57142857142857) displays exactly the correct time that I need…in the simulator only, not on my device :slight_smile:

os.time() returns the number of seconds since Midnight, Jan 1, 1970.  That was 1,409,022,424 just before I started posting this.  If you multiply that by 20 and some change you get a really big number, a value which most likely is overflowing a 32 bit unsigned integer.  While Lua is double floats, this has to get converted back to a UINT when being processed.

I don’t know why you are trying to multiple the number of seconds since midnight, Jan 1, 1970 by 20.57142857142857.

Why does it work in the simulator and not on the device?  Well OS-X and Windows are 64bit operating system and its probably not overflowing, but on the devices, they are likely running in 32 bit space and the max int is 4 billion and change.

Rob

At the time, I was just trying every way I could think of to make it work, and the only way it did, was when I did os.time() * 20.57142857142857 

I also found this following post on a website to work out how to calculate the game time that I need…

To those fellow geeks who would like to know how to calculate Eorzea time based on the local time - take the current time (I’m assuming Epoch format below) and multiply it by 20.57142857142857. As per the above, 1 bell is 3600 Eorzean seconds and 175 Earth seconds, so 3600/175 = 20.57142857142857.

For example, here is what I use in my PHP code:

date_default_timezone_set(‘UTC’); // Use UTC time
print date(“H:i:s”, time()*20.57142857142857); // Provides current Eorzea time

The above post, is where I got the 20.57142857142857 from :) 

This might help explain my problem better, basically, I need to display this time conversion :slight_smile:

http://ffxiv.gamerescape.com/wiki/Time

Are you interested in the time or do you need the date as well?

Just the time, if its easier :) 

okay, what I would suggest then is getting the time stamp for a date in the past that’s not 40 years in the past, like Jan 1, 2010 at midnight.  Then subtract that time in seconds from the current time in sections.  Mulitply that by your constant and either convert that number to your time string needed or if necessary add the the number of seconds back in (though I don’t know that’s really needed).

Rob

Hi Rob,

thanks for the information. I think I understand what you’re saying, but I am a little confused about the subtraction from sections part. What do you mean by sections? Thanks :slight_smile:

EDIT: 

Is this what you meant, Rob? 

-- Get the date of Jan 1, 2010 local now = os.date("\*t") local jan = os.date("\*t", 1262304000) local hour =now.hour - os.time(jan) local min = now.min - os.time(jan) local sec = now.sec - os.time(jan) print(hour)

No, more like:

local jan = os.time( { year=2010, month=1, day=1, hour=0, min=0, sec=0 } ) local now = os.time() local  eorzean = (now - jan) \* 20.57142857142857 + jan local date = os.date( "\*t", eorzean ) print(date.hour .. ":" .. date.min)

You may not need to add the “+ jan” value back in.  I’m not sure.

Rob

Hi Rob, thanks for the reply. Unfortunately, the above code didn’t get the correct time. The current time in-game can be seen from this website: http://www.ffxivclock.com/#/

I tried with the + jan and without it. 

I don’t know whether this would be easier or not, but would it be possible for Corona to read a .PHP file on the web? and display the time that way? I’m not sure how complicated that would be 

If there is a php script that does what you want, you can use network.request() to fetch the file.

Rob

Hi @1991.danielnelson,

You may want to read the following tutorial on working with dates/times:

http://coronalabs.com/blog/2013/01/15/working-with-time-and-dates-in-corona/

Best regards,

Brent

Hi Brent, 

I’ve looked through that tutorial a few times before and have tried most if not all of the methods it contains with no success. I have managed to find different ways of calculating the time I need, but whenever it goes on the device, it doesn’t work. 

It seems to only happen when os.time() is multiplied. I tried os.time() +20.57142857142857) which worked fine on the device, its only when the os.time() is multiplied will it not work. 

I also tried adding the permission android.permission.SET_TIME but discovered that its not possible for an application to request that permission :/ 

What are you trying to do?

Can you post your code that’s not working?

Hi Rob,

local t = os.date("!\*t", os.time() \* 20.57142857142857)

 myText = display.newText( "", 100, 200, native.systemFont, 12 ) myText:setFillColor( 1, 0, 0.5 ) myText.text = "Time: " .. t.hour .. " : " .. t.min .. " : " .. t.sec timer.performWithDelay( 1000, listener, 0)

The above code, does work in the simulator, but not on my Android device. I’m basically trying to find out why it does not work on my phone :slight_smile:

Basically what I need to do is to display the current time of a game that I play. The way I work it out like this: os.date("!*t", os.time() * 20.57142857142857) displays exactly the correct time that I need…in the simulator only, not on my device :slight_smile:

os.time() returns the number of seconds since Midnight, Jan 1, 1970.  That was 1,409,022,424 just before I started posting this.  If you multiply that by 20 and some change you get a really big number, a value which most likely is overflowing a 32 bit unsigned integer.  While Lua is double floats, this has to get converted back to a UINT when being processed.

I don’t know why you are trying to multiple the number of seconds since midnight, Jan 1, 1970 by 20.57142857142857.

Why does it work in the simulator and not on the device?  Well OS-X and Windows are 64bit operating system and its probably not overflowing, but on the devices, they are likely running in 32 bit space and the max int is 4 billion and change.

Rob