Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Unix time stamps and local time

Author
Message
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 9th May 2013 00:09
So I'm trying to get my head around this and it's late in the day and maybe I'm out of brain power...

My app's chat room will need to show a time stamp for the messages.
If I have one user in, say, France and the other in the US what is the best way to get a time stamp for the message so that each user sees when the message was sent in THEIR local time?

If I use unix timestamp I need to somehow determine the user's location to make adjustments... this could be messy.

If I use the functions in AppGameKit then I get their local time, but then I'd have to calculate the difference between that and the unix time on the server to later adjust the time for the receiving user.

Does anyone have a good, simple method for doing this or do I have to have a timestamp from the app AND a unix timestamp for when the server received the message so I can calculate differences to later calculate local time?

OK... off to jump in a blue box and get this figured out with a pro.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th May 2013 02:57
When they send a message, can't you just include an extra byte in the message header containing the GMT offset or timezone that user is located in?

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 9th May 2013 04:24
Sounds good. Where do I get that from without bothering the user?

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th May 2013 04:40
Naphier, since you are using a PHP based server to handle the chat, use the time on your server as the time stamp. And then display any times with an appropriate indicator of the server time. So, if your server is actually on the East coast of the US, add 'EST' or 'EDT' to the time stamp.

But, be careful to be sure that you know the actual time zone for your server. While it is in your home or office, you know for certain. When you to go a hosted service, it might not be the same. JaguarPC, for example, has six separate facilities (and they do own all of their own facilities), one of which is in the UK and the others in Atlanta, New Jersey, Dallas (I think that is where my VPS is), Phoenix and Los Angeles.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 9th May 2013 04:58
That's good to know, but still I need to know the user's specific time zone so that I can adjust the timestamp in the chat to display the correct time for other users.

I found this command for a PHP file
date_default_timezone_set("UTC");

That sounds like I can use that and then any PHP time function calls after that should get me a UTC date/time

Still the problem exists of how to get the user's time zone without actually asking them. I'm thinking that I'll calculate the offset every time messages are grabbed. That way if the change timezones it should be up to date.

Any other ideas and cautionary tales are most welcome!
Thanks for the help so far!

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 9th May 2013 08:07
You should be able to get the client time zone by capturing their IP address on the server and looking at the first groups.

Alternatively, get the current time on the client and send it to the server - you can then get the server time and add or subtract the times to get the offset.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th May 2013 17:03
Capturing the IP and checking works fine as long as they aren't using a proxy. But, if they do that than it is on them.

If you do use the IP to get location, you need to have a disclaimer/warning in your code/privacy statement that you will using the IP for location purposes only to set correct time stamps.

And JimHawkins is right, you can get the local time on the client apps and the following function will return unixtime:


Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 9th May 2013 17:22
Yeah I don't see the need to get it from their IP address.
I'm just going to use GetUnixTime in AppGameKit and then my PHP script will calculate the offset from UTC and log the offset and the UTC time on the server.
Pretty simple.
Thanks for the help thinking this through, everyone!

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th May 2013 20:19
In case you're curious about parsing a unix timestamp into something more readable, there's an example in my zip extractor:
http://forum.thegamecreators.com/?m=forum_view&t=203250&b=6

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 10th May 2013 20:32
Thanks for sharing, but there's commands in AppGameKit that do it too.


GetMonthsFromUnix(), Days, Hours, Seconds... not sure about milliseconds.

I appreciate you thinking of me though

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 10th May 2013 22:04
Here's a bugger:
I'd love to be able to get the day of the week from the Unix time stamp. The AppGameKit command GetDayOfWeek() only gets the info from the device.
I'm probably just going to settle for using the month's name and day number, but this would look sleeker.
Then again I'd have to write more algorithms in to check for the amount of time passed since the message was received so that I can show
Wed 11:12AM only until the next Wednesday when I'd want to show month and day.

Which do you guys think is better to show in a chat program?
Month and day or time elapsed since the message was sent?

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 10th May 2013 22:13
Most chat programs let the user decide how they want to see the date and time stamps. Ugly, but true.

Personally, after four years in Holland and working within an international environment for about 15 years, I prefer day-month-year (10-May-2013). But a lot of folks don't like that.

And the preference for mm/dd/yyyy or dd/mm/yyyy has cause me all sorts of headaches over the years doing genealogy work. The only real clue is if the dd is more than 12.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 11th May 2013 00:15
Quote: "And the preference for mm/dd/yyyy or dd/mm/yyyy has cause me all sorts of headaches over the years doing genealogy work. The only real clue is if the dd is more than 12."

Ah yes quite a classic problem. Months should always be abbreviated to clear up the confusion

I'm sure this doesn't help you in your efforts Naphier, but I always use a time relative to the server startup. In a full chat program this makes less sense, but in a game environment it's a great way to trace when and where things are occuring. Not quite sure what you're making though

swis
Joined: Tue Dec 16th 2008
Interstellar
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 11th May 2013 01:23
My formidable late American sister-in-law was fond of having a go at the Brits. For example, she hated me calling baby marrows courgettes and insisted that they were zucchini in English.

She challenged me on date format: "Why do you get the day and month the wrong way round?"

"Because," I said, "it's more logical to go from the smallest unit (day) to the next biggest (month) and largest (year)."

That was one of very few occasions when she admitted defeat!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th May 2013 01:56
Quote: ""Because," I said, "it's more logical to go from the smallest unit (day) to the next biggest (month) and largest (year).""

My sentiments exactly.

But, then again, we are computer nerds.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 11th May 2013 02:39
I've always felt it was best to go year/month/day, but maybe that's just me. Anyway the game won't likely have a single session last longer than a week so year isn't necessary. I'm not giving players an option on format since there's really no need. I'll probably just go with text month and numerical day. No "sent 4 hours ago" messages. They just take up too much room.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th May 2013 05:02
For sorting, year/month/day is best. But not many places use it as the first option (or even offer it) for basic display.

If you store local information using UTC unix time, you can display however anyone cares about. And it gives you the most options for how you want to deal with it. If you have a known base, all other options are available to you and don't need to be adjusted after the fact.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 11th May 2013 08:58
If you think your software will have a good shelf-life, remember that the current 32-bit Unix time stamp will fail to work in the year 2038.

Slightly less worrying is that a 64-bit time stamp (like Delphi's) will fail to work in December 292,277,026,596

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL

Login to post a reply

Server time is: 2024-11-24 13:56:20
Your offset time is: 2024-11-24 13:56:20