TZ database name for current time zone as a variable

39 kali dilihat
Langsung ke pesan pertama yang belum dibaca

Tom Sherratt

belum dibaca,
17 Sep 2021, 05.39.2817/09/21
kepadaTasker
Does anyone know if it's possible to get the TZ database name for the current time zone of the device as a variable?

So for me, the variable would just be "Europe/London" - helpful as some APIs need this information when inputting a time and at the moment I am having to use a separate API to get this information first.

jmjc...@gmail.com

belum dibaca,
17 Sep 2021, 22.48.2617/09/21
kepadaTasker
Use the ParseDateTime action, check Get All Details, time zone name is in %dt_zone.

Tom Sherratt

belum dibaca,
20 Sep 2021, 10.12.0920/09/21
kepadaTasker
Thanks, I'd never seen this in the Get All Details!

Does anyone know why if you ask it to use the number format 'w' or if you call %dt_week_of_year it doesn't produce the same week number as if you use Java? (Which is suggested to read for the number formats.)

For example, 'w' and %dt_week_of_year give today as week 38 but Java gives today as week 39 and I'd like to be able to get the week as 39 from the ParseDateTime action so I don't have to run Java too.

jmjc...@gmail.com

belum dibaca,
20 Sep 2021, 23.00.4720/09/21
kepadaTasker
It is because they use different calendar settings. ParseDateTime, now you have tested it, uses ISO. For ISO, if Jan 1 falls on a Mon/Tue/Wed/Thu, then it is week #1. If Jan 1 falls on a Fri/Sat/Sun, it is week 53 from last year. Therefore, for 2021, you get 38 from ParseDateTime.

For Java, week number is calculated based on your local settings. If the minimum days in first week is set to 1, as in your case, you get 39. If the minimum days in first week is set to 4, similar to ISO and in other parts of the world, you get 38. Java is more versatile because you can set the minimum days in first week to suit your needs.

If you really don't want to use Java at all and use ParseDateTime, you can always check the week of Jan 01 to see if it returns 53 or 1. If it returns 53, you can then add 1 to %dt_week_of_year.

Tom Sherratt

belum dibaca,
21 Sep 2021, 06.19.5821/09/21
kepadaTasker
Thanks for the explanation!

Is there a more elegant solution to check the week number of 1st January for the current year than getting today's date as a variable and splitting that down to get the year, then prefixing it with "01/01/" and sticking it through ParseDateTime?

jmjc...@gmail.com

belum dibaca,
21 Sep 2021, 08.19.4421/09/21
kepadaTasker
Hmm...one option is to use shell commands. You can use a single Run Shell action that includes a few line commands to do what you want. One command to get the year. One command to get first week's number. One command to get this week's number. One command to add one to this week's number if first week's number is 53. All inside one Run Shell action.

Advantage is you only see ONE action that does everything. But the steps involved are the same as you described above. I usually do this as it looks more organized.

Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru