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 / Tier1 GetCurrentTime issue/question

Author
Message
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 8th May 2012 22:02 Edited at: 8th May 2012 22:04
When I run the Projects/Basic/Examples/Timers/GetDateAndTime example, the time is somewhat odd.

It is showing 4 hours ahead of my local US east coast time. So, I suspect what is being returned is the Greenwich Mean Time, without accounting for Daylight Savings Time.

I suppose this was intentional.

And the extracted day of month is showing one less than it should. Given that many of the unix date functions are zero based for day of month, this is not too unexpected.

I don't expect that this was intentional, as indicated by the documentation.

Sadly, unlike Tier2 programming, AppGameKit basic does not have access to functions like localtime.

So, here is a function that will provide that:


It is up to the calling program to decide what the offset from GMT is (US east coast is -5) and whether it is daylight savings time.

The 'is_dst' parameter is a float so that you can use 0.5 for changing the time by a half hour if you happen to be in one of those places, like South Australia, that change their clocks by half an hour.

It would be nice if there was a 'GetUnixTime' function to return the current unix time directly, so that the process could be simplified a bit.

Cheers,
Ancient Lady
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 8th May 2012 22:08 Edited at: 8th May 2012 22:11
Here is an update with a getunixtime function:


Cheers,
Ancient Lady
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 9th May 2012 00:27
I haven't played with those commands yet, but my expectation would be that they return the current date and time displayed by the device the program is running on.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th May 2012 00:29
It didn't on my windows box. Windows 7, 64bit. All other apps are showing the correct time.

Cheers,
Ancient Lady
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th May 2012 00:58
Just to add to my confusion, I've run the same Projects/Basic/Examples/Timers/GetDateAndTime example on another Windows machine and on an Android device.

The day of month is showing up correctly.

But the hour is still 4 hours off EST.

Cheers,
Ancient Lady
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 14th May 2012 15:51
Ancient Lady, not to criticize, but why go to the trouble of getting unix time? You only need to extract the hours part of the time string, add your zone offset, then put the hours back in the string.

Something like this...



(and I agree, it would be much better to have unix time taken from the device time, instead of building it from the "wrong" current time)

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 14th May 2012 16:41
I plan to use unixtime when storing history data. It is an easy way to keep date and time in one value. I've used it for many years as the simplest value to keep and am used to using it in all the systems I worked with in the satellite business.

We all work within our comfort levels. And then stretch those levels to learn more.

Cheers,
Ancient Lady
AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 14th May 2012 16:56
Rich,

Since I'm a new member on this forum, my posts are
always pending review before they appear on the forums.
So... by the time you read this, I'm sure Ancient Lady
has already given you a reply.. but I'll post anyway.

REVIEW OF PREVIOUS CODE SNIPPET

In your code snippet, your time offset is "-5", right?



What you're doing there, is grabbing the hour part from the
time string, converting it to a value, and subtracting
5 from it (the hardcoded time offset of -5).

If the current time is "01:15:30", for example, what do
you think your adjusted hour will now be?

It won't be "20", it'll be "-4".

You're code snippet is just simply WRONG. Don't use
code like that.

WRAP AROUND

Your code snippet does not properly take into account
how the time will wrap around at the beginning or end
of a day with a positive or a negative time offset.

The functions provided by Ancient Lady properly account
for this wrap-around, and are general purpose functions
withour any hard-coded offset. So you can pretty much
copy/paste them to any code and just call, for example:



Although, I do think the second parameter of Ancient Ladys
"getLocalTime" function should be properly documented,
since, if I am not mistaken, dst offsets can sometimes
be only 30 minutes in some regions. In which case
the is_dst param must be passed as "0.5" (= 30 minutes).

Ancient Ladys code fully accounts for that, but it
isn't very obvious from the parameter naming.

Cheers,
AgentSam
AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 14th May 2012 16:58
Ancient Lady,

When you say "satellite business", what are you referring to?

Just curious,
AgentSam
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 14th May 2012 20:21
Welcome to the forum AgentSam.

I started doing programming for meteorologists, working with satellite and radar data and creating display and manipulation programs for a few years. Then I did some database work for some Goddard satellite systems. Next I got started on satellite simulators and telemetry, command and control systems (as a contractor) for the Naval Research Lab and their friends. I wrote the initial telemetry, command and control code for the first sea launch rocket (not the one that is currently being used to launch satellites). But, we got taken off the project for political reasons (even after my code was validated and approved). So, when they blew the rocket up, it was not our fault. I moved on from there to working at and for Intelsat in DC. There I did the command and telemetry simulators for three series of spacecraft and worked (with others) on the telemetry monitoring and reporting systems and various other systems for dealing with those big things in the sky. From there I went to work at the Intelsat offshoot New Skies Satellites in The Hague, Netherlands. I was the database and system admin for the satellite control systems and the only programmer, creating tools for them to work with the telemetry systems.

I spent 24 years in that environment (and miss it).

Now, I do web sites (PHP, MySQL, Apache in both Linux and Windows) and am trying to get seriously into game programming. I hope to get my first game out by the summer (Mac, iPhone/iPad, Android).

Cheers,
Ancient Lady
AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 14th May 2012 21:02
Thanks.

After some initial confusion about how to keep track of the latest messages (it took awhile to get used to this forum software), I'm already liking this forum a lot.

Also, great bio, a much more complete answer than I expected. Nice job background you have.

When I go on to build my first spacecraft, you're hired - if you're available. I have a few ideas for a mass-acceleration-drive, that need to be tested, but I'm having some problems finding a sufficient portable power source. Your contacts and past experience might come handy.

AgentSam
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 14th May 2012 21:14
This forum is a great place to get help when you need it.

There is almost always someone who can help figure out why something isn't working (always include code snippets of things that don't work right) or come up with ways to get something done.

I come from a long line of engineers and we have fun with techy discussions at family gatherings.

A mass-acceleration-drive sounds like a good thing!

Cheers,
Ancient Lady
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 14th May 2012 22:24
AgentSam - welcome!

And you're right about my code. But it was an off-the-cuff bit of psueudo-code to illustrate what I was talking about.

It just seemed strange to me to use a bad value (the date string) to get another bad value (the unix values) that is modified and then turned back into the date string. Working with just the date string skips the conversion to and from the unix values.

But yeah, my code would need to account for wrapping around, and Ancient Lady's works the way it is.

:0
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 15th May 2012 16:41
My problem isn't with the date value (except as it is affected by being the wrong time zone), it is with the time.

I like having a function that lets me get the local time (Perl and C++ have this and I've used it a lot).

I'm still not sure how I want to get the time zone from the users for any of my Tier1 apps. But, I may decide I don't need it. We'll see.

Cheers,
Ancient Lady
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 16th May 2012 00:05
We have solved this in the latest build 1074, out very soon!

I drink tea, and in my spare time I write software.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 16th May 2012 01:02
At the risk of 'double posting' ....

We love you TGC developers!

Cheers,
Ancient Lady
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 17th May 2012 20:25
I recompiled (commenting out the background image for readability) the 'Timers - GetDateAndTime' Tier1 example.

Well, with 1074, the time now appears correctly. Local time with daylight savings time adjustment. This is an improvement and very welcom.

However, GetCurrentDate returns something very strange.

For today (17-Mar-2012), it returns: 0112-05-17

It looks like the internal processing forgot to add the 1900 (which was once the base year for unixtime stuff).

And when the unix time is created from the date and time pieces, using year=112 and time='13:11:58', and the pieces are extracted, we get the following:
GetYearFromUnix = 2017
GetMonthFromUnix = 10
GetDaysFromUnix = 21

And none of the time from unix functions work right. See attached image.

Naturally, if the ingoing values are bad (like the year not being anywhere within a valid range), the outgoing can be expected to be wrong.

Cheers,
Ancient Lady

Attachments

Login to view attachments
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 18th May 2012 02:35
Quote: "It looks like the internal processing forgot to add the 1900"


That's what I get for not reading documentation properly.

I've fixed this for a future update, but a simple workaround could be to check if it is less than 1900 and if so add 1900. This will work before and after the fix.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 18th May 2012 16:58
That means that we have to check every time we use the GetCurrentDate function.

So, here is a workaround until the next update:


Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-04-27 07:28:11
Your offset time is: 2024-04-27 07:28:11