Lazarus

Free Pascal => Beginners => Topic started by: JLWest on August 06, 2020, 09:11:27 pm

Title: UTC Time question
Post by: JLWest on August 06, 2020, 09:11:27 pm

Is there a way to get the UTC time of say Berlin.

I have the local time in Phoenix and I know the current time offset Berlin.

I can't see a way to determine the UTC time in Berlin.

Thanks.
 
Title: Re: UTC Time question
Post by: TRon on August 06, 2020, 09:29:19 pm
Hello JLWest,

Is there a way to get the UTC time of say Berlin.
Yes, by looking up the timezone (UTF) offset of Berlin.

Quote
I have the local time in Phoenix and I know the current time offset Berlin.
Depends on what you mean exactly by time offset. is that he UTF time offset ?

Quote
I can't see a way to determine the UTC time in Berlin. Usually provided by means of a database, or more correctly using a lang/long map/database of the world

UTC Time location 1 = Local Time Location 1 + UTC time offset location 1
UTC Time location 2 = Local Time Location 2 + UTC time offset location 2

Absolute UTC time duration = UTC Time location 2 - UTC Time location 1

Assuming location 1 is source and location 2 is destination.

edit: oops, corrected an error for the duration. :-[
Title: Re: UTC Time question
Post by: JLWest on August 06, 2020, 09:48:22 pm
Hi TRon

Yes,
I have a file with 24,000 airports with their Lat/Lon of each airport. Also on the record of each airport I have their Current timezone and timezone offest via an API call to TimezoneDB.com.

So for Berlin right now it's CEST 7200,1
Title: Re: UTC Time question
Post by: TRon on August 06, 2020, 09:54:11 pm
So for Berlin right now it's CEST 7200,1
That is problematic because that would mean you need to use yet another timezone offset, namely cest, which is UTC + 2.

There are about a few hundred different named timezones, some or  not including daylight saving time, which makes things unnecessary complicated.

Are you not able to retrieve the UTC time offset of Berlin from that database ?

edit: oh, stupid me. it is 7200 seconds. Usually the offset is provided in minutes, afaik.
Title: Re: UTC Time question
Post by: winni on August 06, 2020, 09:57:21 pm

Is there a way to get the UTC time of say Berlin.

I have the local time in Phoenix and I know the current time offset Berlin.

I can't see a way to determine the UTC time in Berlin.

Thanks.
 


Hi!

The UTC time of Berlin is the same as the UTC time of Phoenix/Arizona.
Or Timbuktu.

That is the definition of UTC time.

To get the UTC from Lazarus do this:

Code: Pascal  [Select][+][-]
  1. uses ......, lazsysutils;
  2.  
  3. .....
  4. ShowMessage (DateTimeToStr(NowUTC));
  5. ....
  6.  

Winni
Title: Re: UTC Time question
Post by: JLWest on August 06, 2020, 10:05:15 pm
UTC Time location 1 = Local Time Location 1 + UTC time offset location 1
UTC Time location 2 = Local Time Location 2 + UTC time offset location 2

Absolute UTC time duration = UTC Time location 2 - UTC Time location 1

This is confusing.

Location 1
 TDT := Now;     = TDateTime                    Not UTC
 MyInt64 := DateTimeToUnix(TDT, True );    Just a EPOCH time

I don't see anything to convert a TDT to UTC


Title: Re: UTC Time question
Post by: winni on August 06, 2020, 10:13:14 pm

Berlin is now 2 hours before UTC (daylight saving)

BerlinTime :=  NowUtC + 2.0/24.0 ;

Arizona is 7 hours behind UTC.
No daylight saving execpt the Navajo Nation (6 hours)

PhoenixTime := NowUTC - 7.0/24.0

That's the whole secret.

Winni
Title: Re: UTC Time question
Post by: JLWest on August 06, 2020, 10:13:26 pm
Hi Winni

Maybe i'm not saying this right.

It's 1308 in Phoenix. What is the local time in Berlin (1008).

All I have is the time code and offset of Berlin. CEST and 7200,1.
Title: Re: UTC Time question
Post by: TRon on August 06, 2020, 10:18:42 pm
UTC Time location 1 = Local Time Location 1 + UTC time offset location 1
UTC Time location 2 = Local Time Location 2 + UTC time offset location 2

Absolute UTC time duration = UTC Time location 2 - UTC Time location 1

This is confusing.
It is perhaps confusing but I wrote down the complete calculation because that way you can always calculate every value when you only have two values to work with.

You asked a similar question in the previous discussion we had, where i suggested to always work with UTC time.

Because as winni wrote, the UTC time is the same everywhere in the world.

The (time) values that differ between two random locations in the world is then their UTC offset.

By the looks of it, your timezone database seem to retrieve the UTC offset including the daylight saving time for Berlin (indicated by the 1 ?)


Quote
I don't see anything to convert a TDT to UTC
See winni's answer.
Title: Re: UTC Time question
Post by: winni on August 06, 2020, 10:26:34 pm
Hi!

Assuming your PC runs with Phoenix time:

The complicated way:
Code: Pascal  [Select][+][-]
  1. UTC := Now + 7.0/24.0;
  2. BerlinTime := UTC -2.0/24.0;

The simple way:
Code: Pascal  [Select][+][-]
  1. BerlinTime := NowUTC - 2.0/24.0;

Winn
Title: Re: UTC Time question
Post by: winni on August 06, 2020, 10:36:12 pm
Hi!

Build  yourself a  clock for Phoenix and Berlin.
You only need a timer and a label.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Timer1Timer(Sender:TObject);
  2. begin
  3. label1.caption := 'Phoenix: 'TimeToStr(NowUTC - 7/24)+ '  Berlin: '+TimeToStr(NowUTC +2/24);
  4. end;

Winni
Title: Re: UTC Time question
Post by: JLWest on August 06, 2020, 10:36:30 pm
                Berlin                     Phoenix
Offset       7200                      -25,200

             7200/60/60 = 2          -25,200/60/60 =  -7

   BT := NowUtC + 2.0/24.0    PT :=  NowUtC -7.0/24.0         

So with offset I can get the UTC. Now I have to get to Local Berlin time.

 

Berlin is now 2 hours before UTC (daylight saving)

BerlinTime :=  NowUtC + 2.0/24.0 ;

Arizona is 7 hours behind UTC.
No daylight saving execpt the Navajo Nation (6 hours)

PhoenixTime := NowUTC - 7.0/24.0

That's the whole secret.

Winni
Title: Re: UTC Time question
Post by: winni on August 06, 2020, 10:44:43 pm
Hi!

Ok - the offset to UTC again in epoch seconds - that was the problem!

And don't  be astonished  about timezones with half an hour:

That's still reality in India, Iran, Australia and others!!

Winni
Title: Re: UTC Time question
Post by: TRon on August 06, 2020, 10:45:58 pm
It's 1308 in Phoenix. What is the local time in Berlin (1008).

That is 22:08 Berlin time btw, not 10:08.

Quote
All I have is the time code and offset of Berlin. CEST and 7200,1.
Again, see winni's answer in case you wish to keep it simple.

Phoenix UTC offset = -7
Berlin UTC offset = +2

Therefor the time difference is 7 (from -7 to 0) + 2 = 9 hours.

13:08 + 9 = 22:08


My calculations come into play when you need to calculate the duration of a flight, which should again be done in UTC time because that is able to provide you with an absolute (duration) value (which is the actual duration of a flight).

You really should try to avoid using local times as much as possible as they do not mean anything. You could just as well state that it is ten pieces of pie later in Berlin then it is in Phoenix. The time difference only exist because humanity decided once that when the sun is at its highest point in the sky it is noonish and that should be the same everywhere in the world (well actually daylight saving time and some other technicalities and politics prevents that from actually being the case).

As of winni's suggestion to build yourself a clock, you can take a peek here: https://time.is/1308_6_Aug_2020_in_Phoenix/Berlin (you can change the places and other settings on the main page.
Title: Re: UTC Time question
Post by: TRon on August 06, 2020, 10:47:47 pm
And don't  be astonished  about timezones with half an hour:
There are even ones of 15 minutes (politics).

I stay out of the discussion now as you seem to have a much clearer head atm and your answers are far more clear  :D

I only seem to confuse user JLWest even further  :-[
Title: Re: UTC Time question
Post by: MarkMLl on August 06, 2020, 10:58:25 pm
If the system were anything like rational The Meridian would run through Florence.

If trying anything clever, be prepared for rounding errors: TDateTime isn't (always) an extended floating point, and so the further we move from the epoch the worse the precision.

MarkMLl
Title: Re: UTC Time question
Post by: winni on August 06, 2020, 11:28:03 pm
Hi!

Yes  - it is awful with "line zero" : There were hard scientific battles if London or Paris will be the "line zero". There were times, when both lines in their sovereign territory were used. Britania then ruled the waves and had won: Greenwich was now "line zero".

And the second awful thing : The planets and the moons don't behave metric. The bloody earth needs 365.2524 day to surround the sun. And the naughty moon does not have a clear relationship to the sun. The only thing already the old greek knew was that the moon is every 18 years nearly at the same position: The great (moon) year.

And the only (?) try to get a metric time was the french revolution. But the metric time never succeeded. The idea was: The day with 10 hours, the hour with 100 minutes, the minute with 100 seconds. This revolution time was never used. In opposite to the metric french revolution calendar, which had a livetime from 1792 to 1805.

Winni
Title: Re: UTC Time question
Post by: JLWest on August 06, 2020, 11:35:48 pm
This time it isn't flight or duration. I want to do an API call for departures and arrivals for about 1000 airports around the world and get as many flights as possible. Doing an API for departures at Berlin at 2:00 am would not yield many flights. Between 9000 and 1000 would a lot better.

Had to included lazutf8sysutils to my use clause.

 Works great.

Phoenix = '8/6/2020 14:30:21'
Berlin    = '8/6/2020 23:30:33'

Thanks


Title: Re: UTC Time question
Post by: winni on August 06, 2020, 11:45:18 pm
Hi!

Nice.

And in some minutes you will have still a "lazy thursday afternoon" but in germany we have a new day. The time goes round and round ...

Winni
Title: Re: UTC Time question
Post by: winni on August 07, 2020, 12:09:20 am
And don't  be astonished  about timezones with half an hour:
There are even ones of 15 minutes (politics).

Hi!

You are right, but that diminished in the last years.
The only countries I know are Nepal and the Chattham Island (belonging to New Zealand).

The other way round is also a problem:
The whole China - in reality 4 timezones - belong to one timezone: Peking time for sure.
And most parts of the EU belong to Berlin time - in reality 3 timezones.

Winni

 
Title: Re: UTC Time question
Post by: TRon on August 07, 2020, 09:22:02 pm
This time it isn't flight or duration.
Ah ok. In that case I'm sorry with regards to my reply, as I initially had the impression that your question(s) where (still) related to duration.

Indeed in that case things work different, but only slightly  :)

Thank you for having taken the time to let me know.
Title: Re: UTC Time question
Post by: JLWest on August 07, 2020, 09:52:11 pm
@TRon Thanks for the reply. I expressed the problem very poorly.

So I just ran the  NowUTC - 7.0/24.0 and it returms 2:48:22 8/8/2020 which seems strange because it's 12:48:22 Local time. 

Is that right?

Title: Re: UTC Time question
Post by: winni on August 07, 2020, 10:03:58 pm
Hi and ???

What you gonna do?

That gives you ~ 13:00 h for Phoenix:

showMessage  (DateTimeToStr(NowUTC - 7/24) );

Winni
Title: Re: UTC Time question
Post by: TRon on August 07, 2020, 10:59:31 pm
So I just ran the  NowUTC - 7.0/24.0 and it returms 2:48:22 8/8/2020 which seems strange because it's 12:48:22 Local time. 

Is that right?
Sorry in case I missed it but I am unable to tell without knowing where exactly you are located (or what UTC offset your current location has).

By looking at the numbers you have provided I can only tell it isn't enough to be able to calculate, unless the UTC offset of your current timezone/location is -7 ?
Title: Re: UTC Time question
Post by: JLWest on August 07, 2020, 11:17:19 pm
yea, I'm in Phoenix and the offset is -7.
Title: Re: UTC Time question
Post by: winni on August 07, 2020, 11:20:43 pm
Hi and ???

What you gonna do?

That gives you ~ 13:00 h for Phoenix:

showMessage  (DateTimeToStr(NowUTC - 7/24) );

Winni
Title: Re: UTC Time question
Post by: JLWest on August 07, 2020, 11:37:44 pm
@Winni

Don't Understand yoir post.

My queston was:

I just ran my program and  NowUTC - 7/24 gives 4:32:14 the Local time is 2:32:14/

Is this right.

Why do we divide by 24?
 
Title: Re: UTC Time question
Post by: winni on August 07, 2020, 11:44:03 pm
Hi!

Because the day has 24 hours.

TDateTime works that  way:

The integer part are days.
The fractional part is the time.
Clock 1 h = 1/24
Clock 5 h = 5/24
Clock 24 = 24/24 = 1 = next day

Got it ?

Winni
Title: Re: UTC Time question
Post by: JLWest on August 07, 2020, 11:53:21 pm
Yea, Got it.

So in theory I can get the UTC time anywhere with NowUTC +/- offset.
With that I can get the local time somehow.

I think you said UTC time is the same time everywhere in the world.
Title: Re: UTC Time question
Post by: winni on August 08, 2020, 12:45:47 am
Hi!

Yes. UTC is the same everywhere in the world. That's why the internal flight plans are always UTC - don't get mixed up with different time zones and daylight savings. For the customers they are then converted to local time.

I mad you - quick and dirty - a small international clock for 10 cities around the world plus UTC. It is in the attachment.

Winni
Title: Re: UTC Time question
Post by: JLWest on August 08, 2020, 12:57:27 am
Thank You.

Just about have this figured out. I sure the clock will help a lot.
Title: Re: UTC Time question
Post by: dbannon on August 08, 2020, 02:25:56 am
> There are even ones of 15 minutes (politics).

The only countries I know are Nepal and the Chattham Island (belonging to New Zealand).

There is also a 15min (actually 45min) increment going up a little west of the centre of Australia. But only about 6 people live there and 2 of those don't have watches.

(sorry to interrupt J)

Davo
Title: Re: UTC Time question
Post by: JLWest on August 08, 2020, 03:12:57 am
@dbannon - LOL

You know the 15, 30, and 45 min changes things a little.

I wont be able to use NowUTC +- Integer / 24 as the calculation but have to do something like this.
I have on the Airport records -420 (Phoenix)

So I divide - 420 by 60 = -7

Bit1 := ExtractWord(8,Airport,[8,['|']);          // -4200

Offset := (StrToInt(Bit1))  / 24;             <=== This would cause a runtime error
                                                                        if it were 7.5 hours or -570
              So

Bit1 := ExtractWord(8,Airport,[8,['|']);          // = '-4200'
Sign := Copy(Bit1,1,1);                               // positive or negative
Bit2 := Copy(Bit1,2,7);                                // Copy just the number   
Bit2 ;= Trim(Bit2);
Offset := (StrToFloat(Bit2))  / 24;                  // Convert to a float and divide by 24
                                                                  // This will handle the odd min

if Sign = '-' then  TDT := NowUTC - Offset
else if Sign = '+' then TDT := NowUTC + Offset;

Title: Re: UTC Time question
Post by: TRon on August 08, 2020, 04:40:32 am
@dbannon
Thank you for making me laugh. btw are you one of those without watch ?  ;)

@JLWest
I understand you took your inspiration from wiini's post, but why so complicated ? You seem to adjust your code to such extend that it somewhat becomes awkward to read/understand :-\

If you retrieve your offset in seconds then why not calculate with seconds ?
Code: Pascal  [Select][+][-]
  1. program UTC_Time1;
  2.  
  3. {$MODE OBJFPC}{$H+}
  4.  
  5. Uses
  6.   sysutils, dateutils, lazsysutils;
  7.  
  8.  
  9. procedure TimmyTime;
  10. var
  11.   here_now                : TDateTime;
  12.   here_UTCOffSet          : int64;  // UTC Offset in seconds
  13.  
  14.   UTC_Now                 : TDateTime;
  15.  
  16.   there_UTCOffsetAsString : string;
  17.   there_UTCOffSet         : int64;  // UTC Offset in seconds
  18.   there_Now               : TDateTime;
  19. begin
  20.   // 'simulate' retrieving local UTC offset from a database record, as a string
  21.   // expressed in seconds.
  22.   there_UTCOffsetAsString := '-4200';
  23.  
  24.   // Convert the local UTC Offset string to an integer value
  25.   there_UTCOffSet := there_UTCOffsetAsString.ToInt64;
  26.  
  27.   // get local time for your current location (for comparison only).
  28.   here_now := Now;
  29.  
  30.   // Get the current UTC time
  31.   UTC_Now := NowUTC;
  32.  
  33.   // get local UTF offset in seconds
  34.   here_UTCOffSet := SecondsBetween(UTC_Now, here_now);
  35.  
  36.   // IncSecond will increase UTC_now with the offset but in case the offset is
  37.   // negative it will actually subtract.
  38.   // We use IncSecond because the actual timeoffset (as String) was provided
  39.   // in seconds.
  40.   there_NOW := IncSecond(UTC_Now,  there_UTCOffSet);
  41.  
  42.   WriteLn('             ', 'Here':20, '   ', 'There');
  43.   WriteLn('  DateTime : ', DateTimeToStr(here_now):20, '   ', DateTimeToStr(there_NOW));
  44.   WriteLn('       UTC : ', DateTimeToStr(UTC_NOW):20 , '   ', DateTimeToStr(UTC_NOW));
  45.   WriteLn('UTC Offset : ', here_UTCOffSet:20         , '   ', there_UTCOffSet);
  46. end;
  47.  
  48. begin
  49.   TimmyTime;
  50. end.
  51.  

Should be easy enough to adapt for use in your (Lazarus) project ?
Title: Re: UTC Time question
Post by: JLWest on August 08, 2020, 05:01:22 am
"// Convert the local UTC Offset string to an integer value
  there_UTCOffSet := there_UTCOffsetAsString.ToInt64;"


Wouldn't this have to be converted to a float to handle 15, 30 and 45 minuets?

But, yea I think yours is cleaner.

Thanks

Ah, no you would't
Title: Re: UTC Time question
Post by: TRon on August 08, 2020, 05:20:11 am
"// Convert the local UTC Offset string to an integer value
  there_UTCOffSet := there_UTCOffsetAsString.ToInt64;"


Wouldn't this have to be converted to a float to handle 15, 30 and 45 minuets?
15 minutes = 15 minutes * 60 seconds per minute = 900 seconds
30 minutes = 30 minutes * 60 seconds per minute = 1800 seconds
45 minutes = 45 minutes * 60 seconds per minute = 2700 seconds

Then we add (or when negative subtract) those seconds to the datetime value using the function incsecond()

I do hope there is not a UTC offset in the world that is smaller than a second (or even smaller) but, in case it does you could even choose to use milliseconds (as my code did in the other thread when we calculated the duration of a flight but that had another reason, namely epoch time which is expressed as an offset of a certain date and time in milliseconds).

In case there are UTC offsets that are smaller than a millisecond (or even smaller) then I actively refuse to take residence on such an insane world and i'll become an astronaut to volunteer for the first manned journey to mars (and I will put up a tent and roast my marsh-mallows there)  :D

Quote
Thanks
No thanks required for providing some inspiration in case it helps.

Quote
Ah, no you would't
I wouldn't what exactly ?
Title: Re: UTC Time question
Post by: TRon on August 08, 2020, 05:41:24 am
@JLWest:
In case you missed it, I am a cheat  ;)

List of UTC time offsets: https://en.wikipedia.org/wiki/List_of_UTC_time_offsets
Title: Re: UTC Time question
Post by: JLWest on August 08, 2020, 05:47:58 am
Quote

"    Ah, no you would't

I wouldn't what exactly ?"

On first read of you code I thought you would have to convert to Float. Then I read it again and realized you don't divide anywhere.  By staying in seconds all the way it handles the odd second's offset 15, 30, and 45.

I think I can convert this to a function and pass an index of the record which is carried in a listbox.  The function would pass back a string of there_UTCOffSet.

Am I correct in thinking that there_UTCoffset is the UTC time of the offset owner. i.e. Berlin.
Title: Re: UTC Time question
Post by: TRon on August 08, 2020, 05:59:16 am
On first read of you code I thought you would have to convert to Float. Then I read it again and realized you don't divide anywhere.  By staying in seconds all the way it handles the odd second's offset 15, 30, and 45.
Ah ok. dumb me could have figured that out himself but somehow missed that you had seen "the light" during your post.

Yes, you understood correctly. We not ever use a smaller entity than seconds, and stay/calculate with those seconds, so there is no need for a float or single/double.

Quote
I think I can convert this to a function and pass an index of the record which is carried in a listbox.  The function would pass back a string of there_UTCOffSet.
Sure, that should be possible. In case that gives you troubles then please post some code and  state what you wish to do with what data exactly and for sure we can come up with a function that works for your case.

Quote
Am I correct in thinking that there_UTCoffset is the UTC time of the offset owner. i.e. Berlin.
That line of thought is absolutely correct.
Title: Re: UTC Time question
Post by: JLWest on August 08, 2020, 06:34:12 am
Actually your code is pretty slick.

 Not saying I won't have any trouble but I think I have a good handle on this now, between you and Winni. 

You know with the data I have 45,000 airports with Lat/Lon, timezone and timezone offset I could build a pretty big world wide clock. All I need is a clock graphic with  movable hands. A little code and my data. You know who is really slick with graphics is handako. I think I found my next project.

You and Winni better stand by. You have given me almost all of the code.

It would make a good tutorial and code example on  the Date and time functions in  FPC/Lazuras. 

Thank you.
Title: Re: UTC Time question
Post by: TRon on August 08, 2020, 06:55:51 am
Actually your code is pretty slick.
Thank you the compliment.

I'm sure you would have been able to (eventually) come up with something similar yourself.

Quote
Not saying I won't have any trouble but I think I have a good handle on this now, between you and Winni. 
In case not then feel free to ask. I'm sure we're not the only ones who would be able to help you out in case of troubles.

Quote
You know with the data I have 45,000 airports with Lat/Lon, timezone and timezone offset I could build a pretty big world wide clock. All I need is a clock graphic with  movable hands. A little code and my data. You know who is really slick with graphics is handako. I think I found my next project.
That could indeed be a very fun project to do. These days there are plenty of websites that are able to do something similar but I find it usually much nicer to be able to do something like that using my own code.

In case you wish to know how to draw a graphical clock... there is a lazarus related blog-site that has a small tutorial on that. I will only post the link in case you are interested, because it could be that you would to try and figure out how to do that yourself first.

Just let me know.

Quote
It would make a good tutorial and code example on  the Date and time functions in  FPC/Lazuras. 
For sure it would.

Have fun !
Title: Re: UTC Time question
Post by: JLWest on August 08, 2020, 07:35:57 am
Yea, I'm interested, When I finish this project that's what we will do. We get handako to build the clock, he's a good guy.

I would have to supply the data records. A lot of them are unusable. You know landing strips on a farm or ranch in Texas. Then I'm using Timezone.com for Timezone information. $5 s month for unlimited usage. We switch to TimezonePascal I think is the name.  Build it and post it on the Form.

Are we going to argue about credits. handako will have the hardest job building the graphics. Then I would have the most time culling 45.000 reccords.

You and Winni just have to write a few lines of code.

So how about "World Clock by handako , JLWest, TRon and winni"  or maybe
"World Clock by handako , JLWest, winni, TRon.

 
Title: Re: UTC Time question
Post by: TRon on August 08, 2020, 08:50:33 am
@JLWest
A world-clock for the community made by the community  :)

There are packages that already include an analogue/digital clock, such as for example Visual PlanIt which you can see here: https://wiki.lazarus.freepascal.org/Turbopower_Visual_PlanIt#TVpClock

And the tutorial about how to make an analogue clock can be found here: https://lazplanet.blogspot.com/2014/06/how-to-make-simple-analog-clock.html

I'm sure there are a lot of visual components packages (for Lazarus) that includes such a clock.

PS: Amazing how those website have the nerve to "offer" you to pay for publicly available information ...  :'(
Title: Re: UTC Time question
Post by: Handoko on August 08, 2020, 09:52:41 am
I didn't follow this thread but I heard there will be a collaborative project and my skill may be needed, that's awesome. I'm in. I should start looking for some ideas on this weekend.

Have a good weekend!
Title: Re: UTC Time question
Post by: JLWest on August 08, 2020, 09:54:54 am
WOW - That's interesting.

I  was thinking of a form with 4 to six clocks and the ability to set each clock to a different city.
Title: Re: UTC Time question
Post by: JLWest on August 08, 2020, 09:56:42 am
I didn't follow this thread but I heard there will be a collaborative project and my skill may be needed, that's awesome. I'm in. I should start looking for some ideas on this weekend.

Have a good weekend!

Great
Title: Re: UTC Time question
Post by: MarkMLl on August 08, 2020, 11:28:02 am
Are we going to argue about credits. handako will have the hardest job building the graphics. Then I would have the most time culling 45.000 reccords.

Presumably you're still keeping that under your hat so I can't check whether the two (possibly three) strips visible from where I am are in it.

MarkMLl
Title: Re: UTC Time question
Post by: winni on August 08, 2020, 01:41:19 pm

There is also a 15min (actually 45min) increment going up a little west of the centre of Australia. But only about 6 people live there and 2 of those don't have watches.


Hi Davo!

You should inform your gvernment.
They don't know about that:

https://info.australia.gov.au/about-australia/facts-and-figures/time-zones-and-daylight-saving (https://info.australia.gov.au/about-australia/facts-and-figures/time-zones-and-daylight-saving)

Winni
Title: Re: UTC Time question
Post by: MarkMLl on August 08, 2020, 02:11:20 pm
https://en.wikipedia.org/wiki/Eucla,_Western_Australia#Time_zone

Population 53. Wp doesn't indicate how many of those are named "Bruce".

MarkMLl
Title: Re: UTC Time question
Post by: winni on August 08, 2020, 02:20:40 pm
Hi!

Allways the biggest problem with different clocks is a source where you can download a maintained table of timezones, daylight saving and its start and end.

The are nearly yearly changes. And a lot of counties have their own algorithm when daylight starts and ends (Israel, Chile, EU.....).

In the last years Russia and Turkey abolished daylight saving.
Portugal changed in the 90s to CET but returned later to UTC.
The half-hour-timezone in Iraq was eleminated after one of the US invasions.

And so on .....

So we need a reliable table to download.
Does anybody know one?

Winni
Title: Re: UTC Time question
Post by: winni on August 08, 2020, 02:26:14 pm
https://en.wikipedia.org/wiki/Eucla,_Western_Australia#Time_zone

Population 53. Wp doesn't indicate how many of those are named "Bruce".

MarkMLl

Nice! And the hottest point of Australia with 49° Celsius.
Too hot to change the time .....

Winni
Title: Re: UTC Time question
Post by: TRon on August 08, 2020, 02:38:52 pm
So we need a reliable table to download.
Does anybody know one?
Iana ? https://www.iana.org/time-zones
Title: Re: UTC Time question
Post by: winni on August 08, 2020, 02:43:44 pm
Hi!

IANAs allways up to date - but you have all the computing by yourself.

I am looking for a "ready to use" table.

Winni
Title: Re: UTC Time question
Post by: winni on August 08, 2020, 02:56:43 pm
Hi!


If found in my sources the body for a analog clock.
The Image should have a size of 90 x 90:

Code: Pascal  [Select][+][-]
  1.   TForm5 = class(TForm)
  2.     Image1: TImage;
  3.     Timer1: TTimer;  
  4.    ....
  5.     procedure Image1Paint(Sender: TObject);
  6.     Procedure Timer1Timer (Sender : TObject);
  7.    .....
  8.   private
  9.     AHour : Word;
  10.     AMin : Word;
  11.     ASec : Word;
  12.    public
  13.    end;
  14.  
  15. const Deg2Rad = pi/180;
  16.  
  17.     Procedure TForm5.Timer1Timer (Sender : TObject);
  18.     var junk : word;
  19.     begin
  20.     DecodeTime(Now,AHour,AMin,ASec,Junk);
  21.     Image1.Invalidate;
  22.     end;            
  23.  
  24. // analog clock, image 90 x 90
  25. procedure TForm5.Image1Paint(Sender: TObject);
  26. const ro=20;    // Minutenzeiger
  27.       centerX=45;
  28.       centerY=47;
  29. var x,y,x1,y1,x2,y2 : integer;
  30.     h,degH, degMin, degSec, sinus, cosinus : single;
  31. begin
  32.   // hours
  33.   h := Ahour;
  34.   if h >=12 then h := h - 12;
  35.   h := h + AMin/60;
  36.   degH :=  h* 30 - 90;   // Uhr (Nord) fängt 90° vor Lazarus (Ost) an
  37.   math.sincos(degH*Deg2Rad, sinus, cosinus);
  38.   x := round (cosinus*ro*0.75)+centerX;
  39.   y := round (sinus *ro*0.75) +CenterY;
  40.   // minutes
  41.   degMin :=  Amin*6 -90;
  42.   math.sincos(degMin*Deg2Rad, sinus, cosinus);
  43.   x1 := round (cosinus*ro)+centerX;
  44.   y1 := round (sinus*ro)+centerY;
  45.   // seconds
  46.   degSec := ASec*6 -90;
  47.   math.sincos(degSec*Deg2Rad, sinus, cosinus);
  48.   x2 := round (cosinus*ro*1.15)+centerX;
  49.   y2 := round (sinus*ro*1.15)+centerY;
  50.   with Image1.Canvas do
  51.       begin
  52.       pen.width := 5;
  53.       pen.Color := clBlack;
  54.       pen.EndCap :=   pecRound;
  55.       line(centerX, centerY,x,y);  // hours
  56.       line(centerX, centerY,x1,y1);   // minutes
  57.       pen.width := 1;
  58.       brush.Color := clLime;
  59.       EllipseC(x,y,3,3);    // radium, luminous lime-green, very 60th
  60.       EllipseC(x1,y1,3,3);
  61.       pen.Color := clRed;
  62.       line(centerX, centerY,x2,y2);    // seconds
  63.       pen.Color := clBlack;
  64.       Brush.color := clSilver;
  65.       EllipseC (centerX, centerY,3,3);
  66.       end;
  67. end;
  68.  
  69.  
  70.  


Must be adapted to NowUTC and the  belonging Timezone.

Have fun!

Winni
Title: Re: UTC Time question
Post by: dbannon on August 08, 2020, 03:02:07 pm

You should inform your gvernment.
They don't know about that:

https://info.australia.gov.au/about-australia/facts-and-figures/time-zones-and-daylight-saving (https://info.australia.gov.au/about-australia/facts-and-figures/time-zones-and-daylight-saving)

You would be surprised at what else they don't know !



Seriously, as you drive across there, you pass two big signs saying to adjust your clocks by, from memory, 45 minutes and then an hour and 15 minutes.  And probably not spoken to anyone in those time zones !

Right now, you cannot even drive across, the border is closed due to the virus !

I don't think JWest needs to allow for those particular time zones in his cals.  But there is a largish town / small city called Broken Hill in the far west of NSW that refuses to use NSW time and works to South Australian time. And it has an airport !

Davo
Title: Re: UTC Time question
Post by: winni on August 08, 2020, 03:08:43 pm

Seriously, as you drive across there, you pass two big signs saying to adjust your clocks by, from memory, 45 minutes and then an hour and 15 minutes.  And probably not spoken to anyone in those time zones !

Davo

Europe is too overcrowded!
Even in Northern Norway, the spanish Estremadura or on the tiny greek islands you won't find anything like that!

Winni
Title: Re: UTC Time question
Post by: MarkMLl on August 08, 2020, 03:12:37 pm
IANAs allways up to date - but you have all the computing by yourself.

I am looking for a "ready to use" table.

If you get something off-the-shelf you'll have difficulty protecting your IP since you haven't added any value.

MarkMLl
Title: Re: UTC Time question
Post by: JLWest on August 08, 2020, 03:14:32 pm
Hi!

IANAs allways up to date - but you have all the computing by yourself.

I am looking for a "ready to use" table.

Winni

What do you want in this table?
Title: Re: UTC Time question
Post by: JLWest on August 08, 2020, 03:23:36 pm
IANAs allways up to date - but you have all the computing by yourself.

I am looking for a "ready to use" table.

If you get something off-the-shelf you'll have difficulty protecting your IP since you haven't added any value.


Are we really concerned about protecting the IP. I thought we would make one as a tutorial example of the Date and time functions. Post it on the form for anyone to use.

Title: Re: UTC Time question
Post by: winni on August 08, 2020, 03:44:07 pm
Hi!

What we need is a table with countries and  their timezones and th daylight saving details - if there are: date and time of start, date and time of end.

There are strange rules like for EU:
Daylight saving starts: last Sunday in March, local time 2:00
Daylight saving end:  last Sunday in October, local time: 2:00

And such rules exist for a lot of different countries - so I'm looking for a table where this is already done.

For the timezones without daylight info I have a solution:

NaturalEarth https://www.naturalearthdata.com (https://www.naturalearthdata.com) offers free vector data (polygons) for countries, rivers ... and for timeszones.
As your airport table contains latitude and logitude we can check with PointInPolygon to which zone a city belongs. But we have no info about daylight .

Winni
Title: Re: UTC Time question
Post by: MarkMLl on August 08, 2020, 03:51:41 pm
Are we really concerned about protecting the IP. I thought we would make one as a tutorial example of the Date and time functions. Post it on the form for anyone to use.

I was just making the point, and if it's a tutorial it could usefully include examples of how to generate its timezone dataset from definitive information.

MarkMLl
Title: Re: UTC Time question
Post by: JLWest on August 08, 2020, 03:55:16 pm
"As your airport table contains latitude and logitude we can check with PointInPolygon to which zone a city belongs. But we have no info about daylight ."

Yes, we do.

I have a Airport text file with 24,000 cities with Lat/Lon and a subscription to TimezoneDB. I do an API call to TimezoneDB and they give me the current Timezone and timezone offset including daylight savings. Cost $5 a month unlimited use. I just ran my 24,000 records thru.

You can get a free subscription but your limited to 1 API call a second.

But why not implement the "The Time Zone Database" (tz or zoneinfo) it has the UTC offsets, and daylight-saving rules.
 
Title: Re: UTC Time question
Post by: dbannon on August 09, 2020, 03:10:37 am
"As your airport table contains latitude and logitude we can check with PointInPolygon to which zone a city belongs. But we have no info about daylight ."

Yes, we do.

I have a Airport text file with 24,000 cities with Lat/Lon and a subscription to TimezoneDB. I do an API call to TimezoneDB and they give me the current Timezone and timezone offset including daylight savings. Cost $5 a month unlimited use. I just ran my 24,000 records thru.

You can get a free subscription but your limited to 1 API call a second.

But why not implement the "The Time Zone Database" (tz or zoneinfo) it has the UTC offsets, and daylight-saving rules.
 

JL, I'd be interested to see if it reports that small city I mentioned earlier, Broken Hill as being in the same timezone as Adelaide or Sydney.  Its in the same state as Sydney but uses Adelaide Time.

Establishing a database would be relatively easy, keeping it current might be a bit harder. On my Linux system I see quite frequent updates to the data on timezones, apparently many places change the days when daylight saving time cuts in or out.  Hmm, wonder where that data comes from ?

Davo
Title: Re: UTC Time question
Post by: JLWest on August 09, 2020, 03:32:38 am
JL, I'd be interested to see if it reports that small city I mentioned earlier, Broken Hill as being in the same timezone as Adelaide or Sydney.  Its in the same state as Sydney but uses Adelaide Time.

I'll see what the TZ and TZoffset is for Broken Hill, Adelaide and Sydney. Take me a bit so stay tuned.

You know you right about keeping the TZ Records current.

Just a thought, We have a dataset (Text Records) of say 45,000 - 50,000.

We don't kept all 50,000 current. You would have a form with 1 to 6 clocks (configurable) on the form. The form would make 1 to 6 API calls and display the local times. That can be done with a free subscription to TimeZoneDB.
Title: Re: UTC Time question
Post by: JLWest on August 09, 2020, 04:25:20 am
@abandon
I had Broken Hill  in the archives. So I made it active which forces the API call to TimeZoneDB.

Broken Hill Timezone = ACST
TimeZone offset = 570 That's 9 and half hours LOL.
Adelaide  is the same but Sydney is AEST and 600

|Broken Hill Airport|-32.001388889|141.471666667|BHQ|YBHI|N|ACST|570|
|Adelaide International Airport|-34.945|138.530555556|ADL|YPAD|N|ACST|570|
|Sydney Int'l Airport|-33.946111111|151.177222222|SYD|YSSY|N|AEST|600|
Title: Re: UTC Time question
Post by: dbannon on August 09, 2020, 12:39:01 pm
Broken Hill Timezone = ACST
TimeZone offset = 570 That's 9 and half hours LOL.
Adelaide  is the same but Sydney is AEST and 600
OK, so its is correct, thats a good thing ! And a touch surprising.

Davo
Title: Re: UTC Time question
Post by: Handoko on August 10, 2020, 04:51:45 am
I made the prototype, should I post it here?

I think the clock should be:
- The UI should be as simple as possible
- It consists of only 2 forms: config form and the form for showing the clocks
- The mainform is the config form
- User can choose how many clocks to be shown
- If user choose 0 clock then it will show the credit page
- The form for the clocks is resizable

Questions:
- Can I use third party graphics library?
- What is the maximum numbers of clocks?
- What should I show on the credit page?
- What is the name of this project?

I quickly made a prototype. Not for now, but later it will be have choose-able skins. Do you guys remember the steampunkclock by @bylaardt? That was awesome.  For better performance I use BGRABitmap, which I believe should have no problem to run on wide range of hardware. To make it easy for beginners to study I use the old-school style, I do not write new class. And I do not optimize the code for performance.

I (later) will try to move the UI and the drawing module away from mainform, so it will be easy to combine with the time zone synchronization code. Here is how to activate the clock:

Code: Pascal  [Select][+][-]
  1.   frmClocks.SetMainform(Self);
  2.   frmClocks.SetLayout(Row, Col);
  3.   frmClocks.Show;

For now, the demo only shows rotating icons. The clocks is not proportional resized, I will fix this issue later. Anyone please try it on different hardware and OSes. Does it work right? Do you have any suggestions?

Note:
To able to compile it, BGRABitmap need to be installed. Here is how to install BGRABitmap:
Lazarus main menu > Package > Online Package Manager > BGRABitmap > Install > From repository
Title: Re: UTC Time question
Post by: JLWest on August 10, 2020, 05:27:29 am
I have a GDrive. If I could figure out how to use it we could post there. I knew how to use it but they changed it.

I think the clock should be:
- The UI should be as simple as possible         <== YES
- It consists of only 2 forms: config form and the form for showing the clocks
- The mainform is the config form
- User can choose how many clocks to be shown
- If user choose 0 clock then it will show the credit page <== Should be ale to
                                                                                          press a small button
                                                                                         to show the credits.

- The form for the clocks is resizable                              <=== Is that needed ???

Questions:
- Can I use third party graphics library?                         <== My vote YES
- What is the maximum numbers of clocks?                    <== I think 6
- What should I show on the credit page?                       <== Me, you, TRon,Winni
- What is the name of this project?                                <== Don't know

On the config of the clocks form.
I would vote for a small red button you press and the credits would popup.

Lower right of each clock would be a small round object like you would use to set the time. Press it and a listbox with the 50,000 cities would appear with a Tedit below the listbox. The Tedit would allow an incidental search of the listbox.

Somewhere on the clock form we show UTC time.
Title: Re: UTC Time question
Post by: Handoko on August 10, 2020, 05:55:25 am
- The form for the clocks is resizable                              <=== Is that needed ???

The form and the clocks should be resizable. Some users have 1024 x 768 small screen but others may have 2560 x 1600 large screen. If we use a fix size output, it may look too small or to large on certain screens.

Press it and a listbox with the 50,000 cities would appear with a Tedit below the listbox. The Tedit would allow an incidental search of the listbox.

Should not be a problem. I ever made searchable edit/combo box.
Title: Re: UTC Time question
Post by: JLWest on August 10, 2020, 06:05:11 am
OK - resizable it it.
Title: Re: UTC Time question
Post by: TRon on August 10, 2020, 06:11:38 am
- What is the name of this project?                                <== Don't know
Lame suggestion: Clocks around the world-wiser
Title: Re: UTC Time question
Post by: Handoko on August 10, 2020, 06:16:35 am
Sounds good. I'm using it now.
Title: Re: UTC Time question
Post by: TRon on August 10, 2020, 06:42:09 am
Sounds good. I'm using it now.
LOL, great !

Lazarus main menu > Package > Online Package Manager > BGRABitmap > Install > From repository
Yeah... uhm.... that poses a problem for me (which I haven't figured out yet)

Established:
Code: [Select]
$ /home/apps/fpc/3.2.0/bin/arm-linux/fpcres --version
fpcres - resource file converter, version 2.0 [2020/06/08], FPC 3.2.0
Host platform: Linux - arm
Copyright (c) 2008 by Giulio Bernardi.

Lazarus...., non-the-wiser  :D
Code: [Select]
lazarus.pp(165,1) Error: Can't call the resource compiler "/home/apps/fpc/3.2.0/bin/arm-linux/fpcres", switching to external mode

When i see those kind of things, I always wonder if the time has come to wind the clock forward a couple of eons  :)

edit: Lazarus is one greedy sob, eating away all memory by itself. 1GB swap wasn't enough though increasing it helped overcome the issue.
Title: Re: UTC Time question
Post by: TRon on August 10, 2020, 07:43:14 am
Anyone please try it on different hardware
arm
Quote
and OSes.
raspbian 32-bit gtk2

Quote
Does it work right?
Seems to work as intended.

Quote
Do you have any suggestions?
On resizing things flicker a lot, panel name is visible as redrawing of the bitmaps takes place. You an see this pi-3b+ struggle with drawing the images the larger the form becomes.
Title: Re: UTC Time question
Post by: Handoko on August 10, 2020, 07:47:14 am
Thank you for the information.

Do you think we should use LazOpenGLContext? I'm afraid BGRABitmap is not optimized for performance.

Using manual canvas drawing should have better performance but the result won't look good, you know jagged lines. I can do anti-aliased lines but will greatly reduce the performance.

Or maybe
It temporary stop drawing when it detect the resizing event.
Title: Re: UTC Time question
Post by: TRon on August 10, 2020, 07:56:21 am
Do you think we should use LazOpenGLContext? I'm afraid BGRABitmap is not optimize for performance.
Hmz.. that could perhaps be an option.

To put things more in context, I seem to remember a thread here on the forums where someone asked about performance of his game. Another user tested that for him on a pi (Also a pi3 if I remember correctly) and seem to have concluded that the raspbian desktop is not using accelerated drivers.

SO, how much is to blame on bgrabitmap is difficult to tell. I have no idea if it is worth the effort, as this is a pretty out of the ordinary setup to begin with.

What do you think handoko ?
Title: Re: UTC Time question
Post by: Handoko on August 10, 2020, 08:05:29 am
Tonight, I will try to optimize code.

Common flicker issues usually can be solved by painting all the items in one single pass. I will try to modify the code without using panels and then draw all the clocks in a buffer then put it on the screen.

But if the flicker only happens when resizing, I think we can temporary disable the drawing routine when it detect the resizing event.

I will investigate this problem later.
Title: Re: UTC Time question
Post by: JLWest on August 10, 2020, 08:09:27 am
@handoko I running you clock demo.

i make a png of what I have in mind.

Title: Re: UTC Time question
Post by: Handoko on August 10, 2020, 08:10:00 am
i make a png of what I have in mind.

Good.
Title: Re: UTC Time question
Post by: Handoko on August 11, 2020, 07:53:35 pm
CATWW version 0.1 is released:
https://forum.lazarus.freepascal.org/index.php/topic,50989.msg373578.html#msg373578
TinyPortal © 2005-2018