Author Topic: What time is it? for Windows only  (Read 4778 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
What time is it? for Windows only
« on: December 31, 2019, 02:24:07 pm »
Code: QB64: [Select]
  1.  
  2. c$ = "POWERSHELL SYSTEMINFO > TimeZoneList.txt" 'also exists better statement POWERSHELL "Get-TimeZone" BUT THIS IS FOR POWERSHELL 5.0 an newer, so this work not under Windows 7!
  3. PRINT "Please wait, finding your GMT..."
  4. DO UNTIL _FILEEXISTS("TimeZoneList.txt")
  5. OPEN "TimeZoneList.txt" FOR BINARY AS #ff
  6.  
  7.     LINE INPUT #ff, d$
  8.     '   PRINT "Record: "; r;: VPRINT d$, 32, 160
  9.     IF r = 23 THEN
  10.         gmc = INSTR(VPRINT$(d$, 32, 96), "(")
  11.         gmc$ = MID$(VPRINT$(d$, 32, 96), gmc, 11)
  12.         PRINT "Your time zone is: "; gmc$
  13.         sign$ = MID$(gmc$, 5, 1)
  14.         hour$ = MID$(gmc$, 6, 2)
  15.         minu$ = MID$(gmc$, 9, 2)
  16.  
  17.         H = VAL(hour$)
  18.         M = VAL(minu$)
  19.         IF sign$ = "-" THEN H = H * -1
  20.         EXIT WHILE
  21.     END IF
  22.     r = r + 1
  23.  
  24.  
  25. 'time zones shift (gmc) for:
  26. 'Prague = 1: Israel = 2: Moscow = 3: Bangkok = 7: Perth = 8: Tokio = 9: Sydney = 11: Wellington = 13: Brasil = -3: Halifax = -4: Indiana = -5: Mexico = -6: Arizona = -7: Tijuana = -8: Samoa = 14
  27. DATA 1,2,3,7,8,9,11,13,-3,-4,-5,-6,-7,-8,14
  28. DATA Prague,Israel,Moscow,Bangkok,Perth,Tokio,Sydney,Wellington,Brasil,Halifax,Indiana,Mexico,Arizona,Tijuana,Samoa
  29.  
  30. DIM areas(14) AS INTEGER
  31. DIM Hrs(14) AS INTEGER
  32. DIM names(14) AS STRING
  33. FOR a = 0 TO 14
  34.     READ areas(a)
  35. FOR a = 0 TO 14
  36.     READ names(a)
  37.  
  38.  
  39.     LOCATE 4
  40.     T = GETHOUR - H
  41.     FOR dl = 0 TO 14
  42.         nt = T + areas(dl)
  43.         IF nt >= 24 THEN nt = nt - 24
  44.         IF nt < 0 THEN nt = nt + 24
  45.         nt$ = LTRIM$(STR$(nt))
  46.         IF LEN(nt$) < 2 THEN nt$ = "0" + nt$
  47.         Min$ = LTRIM$(STR$(GETMINUTE))
  48.         IF LEN(Min$) < 2 THEN Min$ = "0" + Min$
  49.         sec$ = LTRIM$(STR$(GETSECOND))
  50.         IF LEN(sec$) < 2 THEN sec$ = "0" + sec$
  51.         PRINT "Time in "; names(dl); ":"; TAB(30); nt$; ":"; Min$; ":"; sec$; "  "
  52.     NEXT
  53.  
  54.  
  55. FUNCTION GETHOUR
  56.     GETHOUR = INT(TIMER / 3600)
  57.  
  58. FUNCTION GETMINUTE
  59.     H = INT(TIMER / 3600)
  60.     GETMINUTE = INT(TIMER / 60) - H * 60
  61.  
  62. FUNCTION GETSECOND
  63.     H = INT(TIMER / 3600)
  64.     M = INT(TIMER / 60) - H * 60
  65.     GETSECOND = INT(TIMER - (M * 60 + H * 3600))
  66.  
  67. FUNCTION VPRINT$ (t$, s, e)
  68.     'print visible string ASC start from s, to e
  69.     VPRINT$ = ""
  70.     FOR l = 1 TO LEN(t$)
  71.         IF ASC(t$, l) >= s AND ASC(t$, l) <= e THEN
  72.             VPRINT$ = VPRINT$ + MID$(t$, l, 1)
  73.         END IF
  74.     NEXT
  75.  

 
preview.JPG

 

Edit: found and repaired logical bug
« Last Edit: January 02, 2020, 11:13:45 am by Petr »

Offline amigojapan

  • Newbie
  • Posts: 5
    • View Profile
Re: What time is it? for Windows only
« Reply #1 on: January 02, 2020, 08:33:15 am »
Israel is with an s not a z.... sorry, not really a spell nazi :)

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: What time is it? for Windows only
« Reply #2 on: January 02, 2020, 11:06:37 am »
Repaired! :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: What time is it? for Windows only
« Reply #3 on: January 02, 2020, 02:42:40 pm »
Great job Petr! Recently I was wondering if this was possible in QB64 without first asking the user what Time Zone they are in. I didn't know this was possible.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: What time is it? for Windows only
« Reply #4 on: January 03, 2020, 12:27:23 pm »
Israel is with an s not a z.... sorry, not really a spell nazi :)
And here I would have thought he would have pointed out that it's Tokyo not Tokio...  :P

anyway, Interesting little program Petr!

Maybe you could find a way to add the date change too?
Granted after becoming radioactive I only have a half-life!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: What time is it? for Windows only
« Reply #5 on: January 03, 2020, 01:02:04 pm »
Hi Cobalt,

Tokio as name is correct with "i", can be also "Tokjo", but in Czech, all words with "i" after K are correct with Y. But, because Tokio is the accepted name, so spelling is also accepted and therefore wrote it with "i".

I try add date there and write update. Good idea!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: What time is it? for Windows only
« Reply #6 on: January 04, 2020, 01:00:05 pm »
oh so it is a Czech thing, cause I put Tokio into my search engine just be sure Tokio wasn't a place I'd never heard of before and nothing came up, only Tokyo. but then if its a Czech spelling it would not on my end would it?  :)

Granted after becoming radioactive I only have a half-life!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: What time is it? for Windows only
« Reply #7 on: January 05, 2020, 06:44:57 am »

Hi Cobalt,
With that name Tokyo (Tokio), it's hard. It is a translation of Japanese characters, where it is difficult to grab a clue, which "i" there should be. I enclose a screenshot - the output of a search for the Czech version of Google for the query "Tokio" as a proof. Do you see how much Google confuses us?

 
Tokio.JPG



here is program upgrade. Now contains date and day name for all areas.

Code: QB64: [Select]
  1. c$ = "POWERSHELL SYSTEMINFO > TimeZoneList.txt" 'also exists better statement POWERSHELL "Get-TimeZone" BUT THIS IS FOR POWERSHELL 5.0 an newer, so this work not under Windows 7!
  2. PRINT "Please wait, finding your GMT..."
  3. DO UNTIL _FILEEXISTS("TimeZoneList.txt")
  4. OPEN "TimeZoneList.txt" FOR BINARY AS #ff
  5.  
  6.     LINE INPUT #ff, d$
  7.     IF r = 23 THEN
  8.         gmc = INSTR(VPRINT$(d$, 32, 96), "(")
  9.         gmc$ = MID$(VPRINT$(d$, 32, 96), gmc, 11)
  10.         PRINT "Your time zone is: "; gmc$
  11.         sign$ = MID$(gmc$, 5, 1)
  12.         hour$ = MID$(gmc$, 6, 2)
  13.         minu$ = MID$(gmc$, 9, 2)
  14.         H = VAL(hour$)
  15.         M = VAL(minu$)
  16.         IF sign$ = "-" THEN H = H * -1
  17.         EXIT WHILE
  18.     END IF
  19.     r = r + 1
  20.  
  21.  
  22. 'time zones shift (gmc) for:
  23. 'Prague = 1: Israel = 2: Moscow = 3: Bangkok = 7: Perth = 8: Tokio = 9: Sydney = 11: Wellington = 13: Brasil = -3: Halifax = -4: Indiana = -5: Mexico = -6: Arizona = -7: Tijuana = -8: Samoa = 14
  24. DATA 1,2,3,7,8,9,11,13,-3,-4,-5,-6,-7,-8,14
  25. DATA Prague,Israel,Moscow,Bangkok,Perth,Tokio,Sydney,Wellington,Brasil,Halifax,Indiana,Mexico,Arizona,Tijuana,Samoa
  26.  
  27. DIM areas(14) AS INTEGER
  28. DIM names(14) AS STRING
  29.  
  30. FOR a = 0 TO 14
  31.     READ areas(a)
  32. FOR a = 0 TO 14
  33.     READ names(a)
  34.  
  35.     CLS
  36.     LOCATE 4
  37.     T = GETHOUR - H
  38.     FOR dl = 0 TO 14
  39.         d$ = ""
  40.         nt = T + areas(dl)
  41.         ont = nt
  42.  
  43.         IF nt >= 24 THEN nt = nt - 24
  44.         IF nt < 0 THEN nt = nt + 24
  45.         nt$ = LTRIM$(STR$(nt))
  46.         IF LEN(nt$) < 2 THEN nt$ = "0" + nt$
  47.         Min$ = LTRIM$(STR$(GETMINUTE))
  48.         IF LEN(Min$) < 2 THEN Min$ = "0" + Min$
  49.         sec$ = LTRIM$(STR$(GETSECOND))
  50.         IF LEN(sec$) < 2 THEN sec$ = "0" + sec$
  51.         'date and day name upgrade
  52.         SELECT CASE ISDATE(H, GETHOUR, areas(dl))
  53.             CASE 1
  54.                 IF GETMONTH = 1 AND GETDAY = 1 THEN year2 = GETYEAR - 1: month2 = 12: day2 = 31: ELSE year2 = GETYEAR: month2 = GETMONTH: day2 = GETDAY - 1
  55.                 daynr = GETDAYNR(year2, month2, day2)
  56.                 nd$ = GETDATE$(daynr, year2)
  57.                 d$ = nd$ + ", " + GETDAYNAME$(year2, month2, day2)
  58.                 PRINT year2, month2, day2
  59.             CASE 2
  60.                 d$ = DATE$ + ", " + GETDAYNAME$(GETYEAR, GETMONTH, GETDAY)
  61.             CASE 3
  62.                 IF GETMONTH = 12 AND GETDAY = 31 THEN year2 = GETYEAR + 1: month2 = 1: day2 = 1: ELSE year2 = GETYEAR: month2 = GETMONTH: day2 = GETDAY + 1
  63.                 daynr = GETDAYNR(year2, month2, day2)
  64.                 nd$ = GETDATE$(daynr, year2)
  65.                 d$ = nd$ + ", " + GETDAYNAME$(year2, month2, day2)
  66.         END SELECT
  67.         '---------------------------------
  68.         PRINT "Time in "; names(dl); ":"; TAB(30); nt$; ":"; Min$; ":"; sec$; "  "; d$
  69.     NEXT
  70.     _DISPLAY
  71.  
  72.  
  73.  
  74. '========================================================================================================================================================
  75.  
  76.  
  77. FUNCTION ISDATE (LocalShift, LocalTime, NeighbourShift) 'outputs: 1 = DATE is down to 1 Day, 2 = DATE is the same as local date, 3 = DATE is up to 1 day.
  78.     p = NeighbourShift
  79.     MP = LocalShift
  80.     IF LocalTime = 0 THEN LocalTime = 24
  81.     IF LocalTime + NeighbourShift - LocalShift = 24 THEN ISDATE = 3: EXIT FUNCTION 'add
  82.     gethour2 = LocalTime
  83.     IF p < MP THEN
  84.         Cas = gethour2 - (MP + ABS(p))
  85.         IF Cas < 0 THEN Cas = 24 + Cas
  86.         IF gethour2 - MP < Cas THEN ISDATE = 1 ELSE ISDATE = 2
  87.     END IF
  88.     IF p = MP THEN ISDATE = 2
  89.     IF p > MP THEN
  90.         Cas = gethour2 - MP + p
  91.         IF Cas > 24 THEN Cas = Cas - 24
  92.         IF gethour2 - MP > Cas THEN ISDATE = 3 ELSE ISDATE = 2
  93.     END IF
  94. FUNCTION ISLEAPYEAR (year)
  95.     IF year MOD 4 = 0 AND year MOD 100 THEN ISLEAPYEAR = 1
  96.     IF year MOD 100 = 0 AND year MOD 400 = 0 THEN ISLEAPYEAR = 1
  97. FUNCTION GETYEAR
  98.     GETYEAR = VAL(MID$(DATE$, 7, 4))
  99. FUNCTION GETDAY
  100.     GETDAY = VAL(MID$(DATE$, 4, 2))
  101. FUNCTION GETMONTH
  102.     GETMONTH = VAL(MID$(DATE$, 1, 2))
  103. FUNCTION GETDATE$ (NrOfTheDayInYear, y) 'return date 'YYYYMMDD in year y
  104.     IF ISLEAPYEAR(y) = 0 AND NrOfTheDayInYear > 365 THEN GETDATE$ = "Invalid Value!": EXIT FUNCTION
  105.     IF ISLEAPYEAR(y) AND NrOfTheDayInYear > 366 THEN GETDATE$ = "Invalid Value!": EXIT FUNCTION
  106.     FOR month = 1 TO 12
  107.         IF ISLEAPYEAR(y) = 0 THEN
  108.             SELECT CASE month
  109.                 CASE 1: m = 31
  110.                 CASE 2: m = 28
  111.                 CASE 3: m = 31
  112.                 CASE 4: m = 30
  113.                 CASE 5: m = 31
  114.                 CASE 6: m = 30
  115.                 CASE 7: m = 31
  116.                 CASE 8: m = 31
  117.                 CASE 9: m = 30
  118.                 CASE 10: m = 31
  119.                 CASE 11: m = 30
  120.                 CASE 12: m = 31
  121.             END SELECT
  122.         ELSE
  123.             SELECT CASE month
  124.                 CASE 1: m = 31
  125.                 CASE 2: m = 29
  126.                 CASE 3: m = 31
  127.                 CASE 4: m = 30
  128.                 CASE 5: m = 31
  129.                 CASE 6: m = 30
  130.                 CASE 7: m = 31
  131.                 CASE 8: m = 31
  132.                 CASE 9: m = 30
  133.                 CASE 10: m = 31
  134.                 CASE 11: m = 30
  135.                 CASE 12: m = 31
  136.             END SELECT
  137.         END IF
  138.         oldm = om
  139.         om = om + m
  140.         IF om >= NrOfTheDayInYear AND oldm < NrOfTheDayInYear THEN EXIT FOR
  141.     NEXT
  142.     day = NrOfTheDayInYear - om + m
  143.     day$ = STR$(day): IF LEN(day$) < 3 THEN day$ = "0" + LTRIM$(day$)
  144.     month$ = STR$(month): IF LEN(month$) < 3 THEN month$ = "0" + LTRIM$(month$)
  145.     GETDATE$ = LTRIM$(month$) + "-" + LTRIM$(day$) + "-" + LTRIM$(STR$(y))
  146. FUNCTION GETDAYNR (y, m, d) 'insert year, month and day and function calculate which day in year it is
  147.     FOR month = 1 TO m
  148.         IF ISLEAPYEAR(y) = 0 THEN
  149.             SELECT CASE month
  150.                 CASE 1: m = 31
  151.                 CASE 2: m = 28
  152.                 CASE 3: m = 31
  153.                 CASE 4: m = 30
  154.                 CASE 5: m = 31
  155.                 CASE 6: m = 30
  156.                 CASE 7: m = 31
  157.                 CASE 8: m = 31
  158.                 CASE 9: m = 30
  159.                 CASE 10: m = 31
  160.                 CASE 11: m = 30
  161.                 CASE 12: m = 31
  162.             END SELECT
  163.         ELSE
  164.             SELECT CASE month
  165.                 CASE 1: m = 31
  166.                 CASE 2: m = 29
  167.                 CASE 3: m = 31
  168.                 CASE 4: m = 30
  169.                 CASE 5: m = 31
  170.                 CASE 6: m = 30
  171.                 CASE 7: m = 31
  172.                 CASE 8: m = 31
  173.                 CASE 9: m = 30
  174.                 CASE 10: m = 31
  175.                 CASE 11: m = 30
  176.                 CASE 12: m = 31
  177.             END SELECT
  178.         END IF
  179.         GETDAYNR = GETDAYNR + m
  180.     NEXT
  181.     GETDAYNR = GETDAYNR - (m - d)
  182. FUNCTION GETDAYNAME$ (year, month, day)
  183.     DIM om AS LONG, m AS LONG, days AS LONG
  184.     days = day
  185.     FOR yyr = 1 TO year
  186.         IF yyr = year THEN monthend = month ELSE monthend = 12
  187.         FOR mont = 1 TO monthend
  188.             IF ISLEAPYEAR(yyr) = 0 THEN
  189.                 SELECT CASE mont
  190.                     CASE 1: m = 31
  191.                     CASE 2: m = 28
  192.                     CASE 3: m = 31
  193.                     CASE 4: m = 30
  194.                     CASE 5: m = 31
  195.                     CASE 6: m = 30
  196.                     CASE 7: m = 31
  197.                     CASE 8: m = 31
  198.                     CASE 9: m = 30
  199.                     CASE 10: m = 31
  200.                     CASE 11: m = 30
  201.                     CASE 12: m = 31
  202.                 END SELECT
  203.             ELSE
  204.                 SELECT CASE mont
  205.                     CASE 1: m = 31
  206.                     CASE 2: m = 29
  207.                     CASE 3: m = 31
  208.                     CASE 4: m = 30
  209.                     CASE 5: m = 31
  210.                     CASE 6: m = 30
  211.                     CASE 7: m = 31
  212.                     CASE 8: m = 31
  213.                     CASE 9: m = 30
  214.                     CASE 10: m = 31
  215.                     CASE 11: m = 30
  216.                     CASE 12: m = 31
  217.                 END SELECT
  218.             END IF
  219.             om = m
  220.             days = days + m
  221.         NEXT
  222.     NEXT
  223.     days = days - m - 1
  224.     a = (days MOD 7) '0 = monday
  225.     RESTORE nms
  226.     FOR r = 0 TO a
  227.         READ GETDAYNAME$
  228.     NEXT
  229.     nms:
  230.     DATA Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
  231. FUNCTION GETHOUR
  232.     GETHOUR = INT(TIMER / 3600)
  233. FUNCTION GETMINUTE
  234.     H = INT(TIMER / 3600)
  235.     GETMINUTE = INT(TIMER / 60) - H * 60
  236. FUNCTION GETSECOND
  237.     H = INT(TIMER / 3600)
  238.     M = INT(TIMER / 60) - H * 60
  239.     GETSECOND = INT(TIMER - (M * 60 + H * 3600))
  240. FUNCTION VPRINT$ (t$, s, e)
  241.     'print visible string ASC start from s, to e
  242.     VPRINT$ = ""
  243.     FOR l = 1 TO LEN(t$)
  244.         IF ASC(t$, l) >= s AND ASC(t$, l) <= e THEN
  245.             VPRINT$ = VPRINT$ + MID$(t$, l, 1)
  246.         END IF
  247.     NEXT
  248.  

 
time-date-upgrade.JPG


Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: What time is it? for Windows only
« Reply #8 on: January 05, 2020, 09:48:21 am »
Well, there is one bug (I won't say what, if you test it thoroughly, you will find it), but for today my brain already has enough work with dates, so I'll deal with it later. I also started upgrading my source for lotto program according to this requirement https://www.qb64.org/forum/index.php?topic=2060.msg112899#msg112899, but for today I have enough counting dates.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: What time is it? for Windows only
« Reply #9 on: January 07, 2020, 03:24:13 pm »
The older version here contains bug - in midnight program crash and wrote nonsense.

This new version is repaired and show all correct also if program run over midnight. (Set time to try, not wait... :-) )

Code: QB64: [Select]
  1. c$ = "POWERSHELL SYSTEMINFO > TimeZoneList.txt" 'also exists better statement POWERSHELL "Get-TimeZone" BUT THIS IS FOR POWERSHELL 5.0 an newer, so this work not under Windows 7!
  2. PRINT "Please wait, finding your GMT..."
  3. DO UNTIL _FILEEXISTS("TimeZoneList.txt")
  4. OPEN "TimeZoneList.txt" FOR BINARY AS #ff
  5.  
  6.     LINE INPUT #ff, d$
  7.     IF r = 23 THEN
  8.         gmc = INSTR(VPRINT$(d$, 32, 96), "(")
  9.         gmc$ = MID$(VPRINT$(d$, 32, 96), gmc, 11)
  10.         PRINT "Your time zone is: "; gmc$
  11.         sign$ = MID$(gmc$, 5, 1)
  12.         hour$ = MID$(gmc$, 6, 2)
  13.         minu$ = MID$(gmc$, 9, 2)
  14.         H = VAL(hour$)
  15.         M = VAL(minu$)
  16.         IF sign$ = "-" THEN H = H * -1
  17.         EXIT WHILE
  18.     END IF
  19.     r = r + 1
  20.  
  21.  
  22. 'time zones shift (gmc) for:
  23. 'Prague = 1: Israel = 2: Moscow = 3: Bangkok = 7: Perth = 8: Tokio = 9: Sydney = 11: Wellington = 13: Brasil = -3: Halifax = -4: Indiana = -5: Mexico = -6: Arizona = -7: Tijuana = -8: Samoa = 14
  24. DATA 1,2,3,7,8,9,11,13,-3,-4,-5,-6,-7,-8,14
  25. DATA Prague,Israel,Moscow,Bangkok,Perth,Tokio,Sydney,Wellington,Brasil,Halifax,Indiana,Mexico,Arizona,Tijuana,Samoa
  26.  
  27. DIM areas(14) AS INTEGER
  28. DIM names(14) AS STRING
  29.  
  30. FOR a = 0 TO 14
  31.     READ areas(a)
  32. FOR a = 0 TO 14
  33.     READ names(a)
  34.     PCOPY 1, _DISPLAY
  35.     LOCATE 4
  36.     T = GETHOUR - H
  37.     FOR dl = 0 TO 14
  38.         d$ = ""
  39.         nt = T + areas(dl)
  40.         ont = nt
  41.  
  42.         IF nt >= 24 THEN nt = nt - 24
  43.         IF nt < 0 THEN nt = nt + 24
  44.         nt$ = LTRIM$(STR$(nt))
  45.         IF LEN(nt$) < 2 THEN nt$ = "0" + nt$
  46.         Min$ = LTRIM$(STR$(GETMINUTE))
  47.         IF LEN(Min$) < 2 THEN Min$ = "0" + Min$
  48.         sec$ = LTRIM$(STR$(GETSECOND))
  49.         IF LEN(sec$) < 2 THEN sec$ = "0" + sec$
  50.         'date and day name upgrade
  51.         SELECT CASE ISDATE(H, GETHOUR, areas(dl))
  52.             CASE 1
  53.                 IF GETMONTH = 1 AND GETDAY = 1 THEN year2 = GETYEAR - 1: month2 = 12: day2 = 31: ELSE year2 = GETYEAR: month2 = GETMONTH: day2 = GETDAY - 1
  54.                 daynr = GETDAYNR(year2, month2, day2)
  55.                 nd$ = GETDATE$(daynr, year2)
  56.                 d$ = nd$ + ", " + GETDAYNAME$(year2, month2, day2)
  57.             CASE 2
  58.                 d$ = DATE$ + ", " + GETDAYNAME$(GETYEAR, GETMONTH, GETDAY)
  59.             CASE 3
  60.                 IF GETMONTH = 12 AND GETDAY = 31 THEN year2 = GETYEAR + 1: month2 = 1: day2 = 1: ELSE year2 = GETYEAR: month2 = GETMONTH: day2 = GETDAY + 1
  61.                 daynr = GETDAYNR(year2, month2, day2)
  62.                 nd$ = GETDATE$(daynr, year2)
  63.                 d$ = nd$ + ", " + GETDAYNAME$(year2, month2, day2)
  64.         END SELECT
  65.         '---------------------------------
  66.         PRINT "Time in "; names(dl); ":"; TAB(30); nt$; ":"; Min$; ":"; sec$; "  "; d$
  67.     NEXT
  68.     _DISPLAY
  69.  
  70.  
  71.  
  72. '========================================================================================================================================================
  73.  
  74.  
  75. FUNCTION ISDATE (LShift, LocalTime, NShift) 'outputs: 1 = DATE is down to 1 Day, 2 = DATE is the same as local date, 3 = DATE is up to 1 day.
  76.     'LShift = Local Time Zone (POWERSHELL output), Local Time (Hour in this example), NShift = Other Timer Zone (neighbor zone) time shift
  77.  
  78.     'calculate real time shift between zones (computer zone / neighbor zone)
  79.     Tzone = NShift 'pro pasmo 0
  80.     IF NShift > 0 THEN Tzone = NShift - LShift
  81.     IF NShift < 0 THEN Tzone = -1 * ABS(NShift - LShift)
  82.  
  83.  
  84.     IF NShift = 0 THEN ISDATE = 2: EXIT FUNCTION 'local time, local computer
  85.     IF NShift > 0 THEN 'zone PLUS
  86.         IF LocalTime + Tzone >= 24 THEN ISDATE = 3 ELSE ISDATE = 2 'I am from time zone +1. So for example, Israel is time zone +2. If in my zone is 23:00, my zone use old date, but Israel use new date in the same time,
  87.         '                                                           because there is midnight. Real time shift between Czech republic and Israel is one hour.
  88.     END IF
  89.  
  90.     IF NShift < 0 THEN ' zone MINUS
  91.         IF LocalTime + Tzone >= 0 THEN ISDATE = 2 ELSE ISDATE = 1
  92.     END IF
  93.  
  94. FUNCTION ISLEAPYEAR (year)
  95.     IF year MOD 4 = 0 AND year MOD 100 THEN ISLEAPYEAR = 1
  96.     IF year MOD 100 = 0 AND year MOD 400 = 0 THEN ISLEAPYEAR = 1
  97. FUNCTION GETYEAR
  98.     GETYEAR = VAL(MID$(DATE$, 7, 4))
  99. FUNCTION GETDAY
  100.     GETDAY = VAL(MID$(DATE$, 4, 2))
  101. FUNCTION GETMONTH
  102.     GETMONTH = VAL(MID$(DATE$, 1, 2))
  103. FUNCTION GETDATE$ (NrOfTheDayInYear, y) 'return date 'YYYYMMDD in year y
  104.     IF ISLEAPYEAR(y) = 0 AND NrOfTheDayInYear > 365 THEN GETDATE$ = "Invalid Value!": EXIT FUNCTION
  105.     IF ISLEAPYEAR(y) AND NrOfTheDayInYear > 366 THEN GETDATE$ = "Invalid Value!": EXIT FUNCTION
  106.     FOR month = 1 TO 12
  107.         IF ISLEAPYEAR(y) = 0 THEN
  108.             SELECT CASE month
  109.                 CASE 1: m = 31
  110.                 CASE 2: m = 28
  111.                 CASE 3: m = 31
  112.                 CASE 4: m = 30
  113.                 CASE 5: m = 31
  114.                 CASE 6: m = 30
  115.                 CASE 7: m = 31
  116.                 CASE 8: m = 31
  117.                 CASE 9: m = 30
  118.                 CASE 10: m = 31
  119.                 CASE 11: m = 30
  120.                 CASE 12: m = 31
  121.             END SELECT
  122.         ELSE
  123.             SELECT CASE month
  124.                 CASE 1: m = 31
  125.                 CASE 2: m = 29
  126.                 CASE 3: m = 31
  127.                 CASE 4: m = 30
  128.                 CASE 5: m = 31
  129.                 CASE 6: m = 30
  130.                 CASE 7: m = 31
  131.                 CASE 8: m = 31
  132.                 CASE 9: m = 30
  133.                 CASE 10: m = 31
  134.                 CASE 11: m = 30
  135.                 CASE 12: m = 31
  136.             END SELECT
  137.         END IF
  138.         oldm = om
  139.         om = om + m
  140.         IF om >= NrOfTheDayInYear AND oldm < NrOfTheDayInYear THEN EXIT FOR
  141.     NEXT
  142.     day = NrOfTheDayInYear - om + m
  143.     day$ = STR$(day): IF LEN(day$) < 3 THEN day$ = "0" + LTRIM$(day$)
  144.     month$ = STR$(month): IF LEN(month$) < 3 THEN month$ = "0" + LTRIM$(month$)
  145.     GETDATE$ = LTRIM$(month$) + "-" + LTRIM$(day$) + "-" + LTRIM$(STR$(y))
  146. FUNCTION GETDAYNR (y, m, d) 'insert year, month and day and function calculate which day in year it is
  147.     FOR month = 1 TO m
  148.         IF ISLEAPYEAR(y) = 0 THEN
  149.             SELECT CASE month
  150.                 CASE 1: m = 31
  151.                 CASE 2: m = 28
  152.                 CASE 3: m = 31
  153.                 CASE 4: m = 30
  154.                 CASE 5: m = 31
  155.                 CASE 6: m = 30
  156.                 CASE 7: m = 31
  157.                 CASE 8: m = 31
  158.                 CASE 9: m = 30
  159.                 CASE 10: m = 31
  160.                 CASE 11: m = 30
  161.                 CASE 12: m = 31
  162.             END SELECT
  163.         ELSE
  164.             SELECT CASE month
  165.                 CASE 1: m = 31
  166.                 CASE 2: m = 29
  167.                 CASE 3: m = 31
  168.                 CASE 4: m = 30
  169.                 CASE 5: m = 31
  170.                 CASE 6: m = 30
  171.                 CASE 7: m = 31
  172.                 CASE 8: m = 31
  173.                 CASE 9: m = 30
  174.                 CASE 10: m = 31
  175.                 CASE 11: m = 30
  176.                 CASE 12: m = 31
  177.             END SELECT
  178.         END IF
  179.         GETDAYNR = GETDAYNR + m
  180.     NEXT
  181.     GETDAYNR = GETDAYNR - (m - d)
  182. FUNCTION GETDAYNAME$ (year, month, day)
  183.     DIM om AS LONG, m AS LONG, days AS LONG
  184.     days = day
  185.     FOR yyr = 1 TO year
  186.         IF yyr = year THEN monthend = month ELSE monthend = 12
  187.         FOR mont = 1 TO monthend
  188.             IF ISLEAPYEAR(yyr) = 0 THEN
  189.                 SELECT CASE mont
  190.                     CASE 1: m = 31
  191.                     CASE 2: m = 28
  192.                     CASE 3: m = 31
  193.                     CASE 4: m = 30
  194.                     CASE 5: m = 31
  195.                     CASE 6: m = 30
  196.                     CASE 7: m = 31
  197.                     CASE 8: m = 31
  198.                     CASE 9: m = 30
  199.                     CASE 10: m = 31
  200.                     CASE 11: m = 30
  201.                     CASE 12: m = 31
  202.                 END SELECT
  203.             ELSE
  204.                 SELECT CASE mont
  205.                     CASE 1: m = 31
  206.                     CASE 2: m = 29
  207.                     CASE 3: m = 31
  208.                     CASE 4: m = 30
  209.                     CASE 5: m = 31
  210.                     CASE 6: m = 30
  211.                     CASE 7: m = 31
  212.                     CASE 8: m = 31
  213.                     CASE 9: m = 30
  214.                     CASE 10: m = 31
  215.                     CASE 11: m = 30
  216.                     CASE 12: m = 31
  217.                 END SELECT
  218.             END IF
  219.             om = m
  220.             days = days + m
  221.         NEXT
  222.     NEXT
  223.     days = days - m - 1
  224.     a = (days MOD 7) '0 = monday
  225.     RESTORE nms
  226.     FOR r = 0 TO a
  227.         READ GETDAYNAME$
  228.     NEXT
  229.     nms:
  230.     DATA Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
  231. FUNCTION GETHOUR
  232.     GETHOUR = INT(TIMER / 3600)
  233. FUNCTION GETMINUTE
  234.     H = INT(TIMER / 3600)
  235.     GETMINUTE = INT(TIMER / 60) - H * 60
  236. FUNCTION GETSECOND
  237.     H = INT(TIMER / 3600)
  238.     M = INT(TIMER / 60) - H * 60
  239.     GETSECOND = INT(TIMER - (M * 60 + H * 3600))
  240. FUNCTION VPRINT$ (t$, s, e)
  241.     'print visible string ASC start from s, to e
  242.     VPRINT$ = ""
  243.     FOR l = 1 TO LEN(t$)
  244.         IF ASC(t$, l) >= s AND ASC(t$, l) <= e THEN
  245.             VPRINT$ = VPRINT$ + MID$(t$, l, 1)
  246.         END IF
  247.     NEXT
  248.  

And when I finally managed to fix it so nicely (I have to praise myself, guys, I already have one beer as reward on my desk) but now it is time to modify the program for the Lotto program for rcamp48. It will take a while again.

 
smile.jpg
« Last Edit: January 07, 2020, 05:31:28 pm by Petr »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: What time is it? for Windows only
« Reply #11 on: January 08, 2020, 08:20:03 am »
Perfect idea, Steve! Here is my result:

Code: QB64: [Select]
  1. PRINT GETTIMEZONE
  2.  
  3. FUNCTION GETTIMEZONE
  4.     DECLARE DYNAMIC LIBRARY "Kernel32"
  5.         SUB GetTimeZoneInformation (a AS INTEGER)
  6.     END DECLARE
  7.     DIM b AS INTEGER
  8.     GetTimeZoneInformation b
  9.     GETTIMEZONE = b / -60
  10.  

I add it to sources here later. Thank you again!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: What time is it? for Windows only
« Reply #12 on: January 08, 2020, 05:07:59 pm »
Final version, without PowerShell.

Code: QB64: [Select]
  1.  
  2. PRINT "Please wait, finding your GMT..."
  3. H = GETTIMEZONE
  4. IF H > 0 THEN zone$ = "GMT +" + LTRIM$(STR$(H)) ELSE zone$ = "GMT " + LTRIM$(STR$(H))
  5. PRINT "Your time zone is: "; zone$
  6.  
  7. 'time zones shift (gmc) for:
  8. 'Prague = 1: Israel = 2: Moscow = 3: Bangkok = 7: Perth = 8: Tokio = 9: Sydney = 11: Wellington = 13: Brasil = -3: Halifax = -4: Indiana = -5: Mexico = -6: Arizona = -7: Tijuana = -8: Samoa = 14
  9. DATA 1,2,3,7,8,9,11,13,-3,-4,-5,-6,-7,-8,14
  10. DATA Prague,Israel,Moscow,Bangkok,Perth,Tokio,Sydney,Wellington,Brasil,Halifax,Indiana,Mexico,Arizona,Tijuana,Samoa
  11.  
  12. DIM areas(14) AS INTEGER
  13. DIM names(14) AS STRING
  14.  
  15. FOR a = 0 TO 14
  16.     READ areas(a)
  17. FOR a = 0 TO 14
  18.     READ names(a)
  19.     PCOPY 1, _DISPLAY
  20.     LOCATE 4
  21.     T = GETHOUR - H
  22.     FOR dl = 0 TO 14
  23.         d$ = ""
  24.         nt = T + areas(dl)
  25.         ont = nt
  26.  
  27.         IF nt >= 24 THEN nt = nt - 24
  28.         IF nt < 0 THEN nt = nt + 24
  29.         nt$ = LTRIM$(STR$(nt))
  30.         IF LEN(nt$) < 2 THEN nt$ = "0" + nt$
  31.         Min$ = LTRIM$(STR$(GETMINUTE))
  32.         IF LEN(Min$) < 2 THEN Min$ = "0" + Min$
  33.         sec$ = LTRIM$(STR$(GETSECOND))
  34.         IF LEN(sec$) < 2 THEN sec$ = "0" + sec$
  35.         'date and day name upgrade
  36.         SELECT CASE ISDATE(H, GETHOUR, areas(dl))
  37.             CASE 1
  38.                 IF GETMONTH = 1 AND GETDAY = 1 THEN year2 = GETYEAR - 1: month2 = 12: day2 = 31: ELSE year2 = GETYEAR: month2 = GETMONTH: day2 = GETDAY - 1
  39.                 daynr = GETDAYNR(year2, month2, day2)
  40.                 nd$ = GETDATE$(daynr, year2)
  41.                 d$ = nd$ + ", " + GETDAYNAME$(year2, month2, day2)
  42.             CASE 2
  43.                 d$ = DATE$ + ", " + GETDAYNAME$(GETYEAR, GETMONTH, GETDAY)
  44.             CASE 3
  45.                 IF GETMONTH = 12 AND GETDAY = 31 THEN year2 = GETYEAR + 1: month2 = 1: day2 = 1: ELSE year2 = GETYEAR: month2 = GETMONTH: day2 = GETDAY + 1
  46.                 daynr = GETDAYNR(year2, month2, day2)
  47.                 nd$ = GETDATE$(daynr, year2)
  48.                 d$ = nd$ + ", " + GETDAYNAME$(year2, month2, day2)
  49.         END SELECT
  50.         '---------------------------------
  51.         PRINT "Time in "; names(dl); ":"; TAB(30); nt$; ":"; Min$; ":"; sec$; "  "; d$
  52.     NEXT
  53.     _DISPLAY
  54.  
  55.  
  56.  
  57. '========================================================================================================================================================
  58.  
  59.  
  60. FUNCTION ISDATE (LShift, LocalTime, NShift) 'outputs: 1 = DATE is down to 1 Day, 2 = DATE is the same as local date, 3 = DATE is up to 1 day.
  61.     'LShift = Local Time Zone (POWERSHELL output), Local Time (Hour in this example), NShift = Other Timer Zone (neighbor zone) time shift
  62.  
  63.     'calculate real time shift between zones (computer zone / neighbor zone)
  64.     Tzone = NShift 'pro pasmo 0
  65.     IF NShift > 0 THEN Tzone = NShift - LShift
  66.     IF NShift < 0 THEN Tzone = -1 * ABS(NShift - LShift)
  67.  
  68.  
  69.     IF NShift = 0 THEN ISDATE = 2: EXIT FUNCTION 'local time, local computer
  70.     IF NShift > 0 THEN 'zone PLUS
  71.         IF LocalTime + Tzone >= 24 THEN ISDATE = 3 ELSE ISDATE = 2 'I am from time zone +1. So for example, Israel is time zone +2. If in my zone is 23:00, my zone use old date, but Israel use new date in the same time,
  72.         '                                                           because there is midnight. Real time shift between Czech republic and Israel is one hour.
  73.     END IF
  74.  
  75.     IF NShift < 0 THEN ' zone MINUS
  76.         IF LocalTime + Tzone >= 0 THEN ISDATE = 2 ELSE ISDATE = 1
  77.     END IF
  78.  
  79. FUNCTION ISLEAPYEAR (year)
  80.     IF year MOD 4 = 0 AND year MOD 100 THEN ISLEAPYEAR = 1
  81.     IF year MOD 100 = 0 AND year MOD 400 = 0 THEN ISLEAPYEAR = 1
  82. FUNCTION GETYEAR
  83.     GETYEAR = VAL(MID$(DATE$, 7, 4))
  84. FUNCTION GETDAY
  85.     GETDAY = VAL(MID$(DATE$, 4, 2))
  86. FUNCTION GETMONTH
  87.     GETMONTH = VAL(MID$(DATE$, 1, 2))
  88. FUNCTION GETDATE$ (NrOfTheDayInYear, y) 'return date 'YYYYMMDD in year y
  89.     IF ISLEAPYEAR(y) = 0 AND NrOfTheDayInYear > 365 THEN GETDATE$ = "Invalid Value!": EXIT FUNCTION
  90.     IF ISLEAPYEAR(y) AND NrOfTheDayInYear > 366 THEN GETDATE$ = "Invalid Value!": EXIT FUNCTION
  91.     FOR month = 1 TO 12
  92.         IF ISLEAPYEAR(y) = 0 THEN
  93.             SELECT CASE month
  94.                 CASE 1: m = 31
  95.                 CASE 2: m = 28
  96.                 CASE 3: m = 31
  97.                 CASE 4: m = 30
  98.                 CASE 5: m = 31
  99.                 CASE 6: m = 30
  100.                 CASE 7: m = 31
  101.                 CASE 8: m = 31
  102.                 CASE 9: m = 30
  103.                 CASE 10: m = 31
  104.                 CASE 11: m = 30
  105.                 CASE 12: m = 31
  106.             END SELECT
  107.         ELSE
  108.             SELECT CASE month
  109.                 CASE 1: m = 31
  110.                 CASE 2: m = 29
  111.                 CASE 3: m = 31
  112.                 CASE 4: m = 30
  113.                 CASE 5: m = 31
  114.                 CASE 6: m = 30
  115.                 CASE 7: m = 31
  116.                 CASE 8: m = 31
  117.                 CASE 9: m = 30
  118.                 CASE 10: m = 31
  119.                 CASE 11: m = 30
  120.                 CASE 12: m = 31
  121.             END SELECT
  122.         END IF
  123.         oldm = om
  124.         om = om + m
  125.         IF om >= NrOfTheDayInYear AND oldm < NrOfTheDayInYear THEN EXIT FOR
  126.     NEXT
  127.     day = NrOfTheDayInYear - om + m
  128.     day$ = STR$(day): IF LEN(day$) < 3 THEN day$ = "0" + LTRIM$(day$)
  129.     month$ = STR$(month): IF LEN(month$) < 3 THEN month$ = "0" + LTRIM$(month$)
  130.     GETDATE$ = LTRIM$(month$) + "-" + LTRIM$(day$) + "-" + LTRIM$(STR$(y))
  131. FUNCTION GETDAYNR (y, m, d) 'insert year, month and day and function calculate which day in year it is
  132.     FOR month = 1 TO m
  133.         IF ISLEAPYEAR(y) = 0 THEN
  134.             SELECT CASE month
  135.                 CASE 1: m = 31
  136.                 CASE 2: m = 28
  137.                 CASE 3: m = 31
  138.                 CASE 4: m = 30
  139.                 CASE 5: m = 31
  140.                 CASE 6: m = 30
  141.                 CASE 7: m = 31
  142.                 CASE 8: m = 31
  143.                 CASE 9: m = 30
  144.                 CASE 10: m = 31
  145.                 CASE 11: m = 30
  146.                 CASE 12: m = 31
  147.             END SELECT
  148.         ELSE
  149.             SELECT CASE month
  150.                 CASE 1: m = 31
  151.                 CASE 2: m = 29
  152.                 CASE 3: m = 31
  153.                 CASE 4: m = 30
  154.                 CASE 5: m = 31
  155.                 CASE 6: m = 30
  156.                 CASE 7: m = 31
  157.                 CASE 8: m = 31
  158.                 CASE 9: m = 30
  159.                 CASE 10: m = 31
  160.                 CASE 11: m = 30
  161.                 CASE 12: m = 31
  162.             END SELECT
  163.         END IF
  164.         GETDAYNR = GETDAYNR + m
  165.     NEXT
  166.     GETDAYNR = GETDAYNR - (m - d)
  167. FUNCTION GETDAYNAME$ (year, month, day)
  168.     DIM om AS LONG, m AS LONG, days AS LONG
  169.     days = day
  170.     FOR yyr = 1 TO year
  171.         IF yyr = year THEN monthend = month ELSE monthend = 12
  172.         FOR mont = 1 TO monthend
  173.             IF ISLEAPYEAR(yyr) = 0 THEN
  174.                 SELECT CASE mont
  175.                     CASE 1: m = 31
  176.                     CASE 2: m = 28
  177.                     CASE 3: m = 31
  178.                     CASE 4: m = 30
  179.                     CASE 5: m = 31
  180.                     CASE 6: m = 30
  181.                     CASE 7: m = 31
  182.                     CASE 8: m = 31
  183.                     CASE 9: m = 30
  184.                     CASE 10: m = 31
  185.                     CASE 11: m = 30
  186.                     CASE 12: m = 31
  187.                 END SELECT
  188.             ELSE
  189.                 SELECT CASE mont
  190.                     CASE 1: m = 31
  191.                     CASE 2: m = 29
  192.                     CASE 3: m = 31
  193.                     CASE 4: m = 30
  194.                     CASE 5: m = 31
  195.                     CASE 6: m = 30
  196.                     CASE 7: m = 31
  197.                     CASE 8: m = 31
  198.                     CASE 9: m = 30
  199.                     CASE 10: m = 31
  200.                     CASE 11: m = 30
  201.                     CASE 12: m = 31
  202.                 END SELECT
  203.             END IF
  204.             om = m
  205.             days = days + m
  206.         NEXT
  207.     NEXT
  208.     days = days - m - 1
  209.     a = (days MOD 7) '0 = monday
  210.     RESTORE nms
  211.     FOR r = 0 TO a
  212.         READ GETDAYNAME$
  213.     NEXT
  214.     nms:
  215.     DATA Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
  216. FUNCTION GETHOUR
  217.     GETHOUR = INT(TIMER / 3600)
  218. FUNCTION GETMINUTE
  219.     H = INT(TIMER / 3600)
  220.     GETMINUTE = INT(TIMER / 60) - H * 60
  221. FUNCTION GETSECOND
  222.     H = INT(TIMER / 3600)
  223.     M = INT(TIMER / 60) - H * 60
  224.     GETSECOND = INT(TIMER - (M * 60 + H * 3600))
  225.  
  226. FUNCTION GETTIMEZONE
  227.     DECLARE DYNAMIC LIBRARY "Kernel32"
  228.         SUB GetTimeZoneInformation (a AS INTEGER)
  229.     END DECLARE
  230.     DIM b AS INTEGER
  231.     GetTimeZoneInformation b
  232.     GETTIMEZONE = b / -60
  233.