Add time zone capability to buici clock

Asked by rosorio975 on 2020-01-20

Hi Marc,

I did some changes to the buici-clock in order to be able to specify a time zone / country
whose date we want to display the time. The current syntax is the -tz switch followed by
the tz you wanna use in the zoneinfo/zone1970.tab format.

As an example, if I wanna launch a buici-clock displaying the Phoenix time in the USA,
the command line will be:

buici-clock -tz America/Phoenix

I don't know what's the better way way to submit a patch, so I attach it at the end of this message.
Let me know if you are interested by merging such changes or not.

All the best,
-- rodrigo

diff --git a/clock.cxx b/clock.cxx
index fc9c03a..4ac4d73 100644
--- a/clock.cxx
+++ b/clock.cxx
@@ -91,6 +91,7 @@
 //#define USE_LOCAL_GC // Cache our own GC

 extern char* g_szApplication; // Name of application
+extern char* g_szTimeZone;
 bool g_fQuit;
 extern int g_fAsDesktop;
 extern int g_fAsToolbar;
@@ -888,6 +889,12 @@ int do_clock (void)
   int y = 0;
   unsigned int dx = 100;
   unsigned int dy = 100;
+ char buf[80];
+
+ if (g_szTimeZone) {
+ setenv("TZ",g_szTimeZone , 1);
+ putenv(buf);
+ tzset();
+ }

   {
     LDisplay display;
diff --git a/main.cxx b/main.cxx
index c5bb0df..b82d704 100644
--- a/main.cxx
+++ b/main.cxx
@@ -57,6 +57,7 @@ int g_fAsDock;
 int g_fOverrideRedirect;
 int g_showSecondHand = -1; // -1 means use the resource or default to true
 char* g_szGeometry;
+char* g_szTimeZone = NULL;

 OPTION rgOptions[] =
 {
@@ -66,6 +67,7 @@ OPTION rgOptions[] =
   { "as-toolbar", OptSetInt, &g_fAsToolbar },
   { "override-redirect", OptSetInt, &g_fOverrideRedirect },
   { "show-second-hand", OptArg | OptSetInt, &g_showSecondHand },
+ { "tz", OptArg | OptSetString | OptAllDash, &g_szTimeZone },
   { "help", 0, NULL, do_usage },
   { "h", 0, NULL, do_usage },

@@ -102,6 +104,7 @@ int do_usage (OPTION*, const char*)
 " --no-override Suppress window manager control by\n"
 " inhibiting override-redirect\n"
 " --show-second-hand=0|1 Hide or show the second hand. Overrides resource.\n"
+" --tz Set the selected time zone\n"
 " --version, -V Display version and copyright\n"
 " --help, -h Usage message\n"
 /* " (*) Default option\n" */

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu buici-clock Edit question
Assignee:
No assignee Edit question
Solved by:
rosorio975
Solved:
2020-01-21
Last query:
2020-01-21
Last reply:
2020-01-21
Manfred Hampl (m-hampl) said : #1

Ubuntu has copied this package from Debian.
I suggest that you create a bug report in Debian with your suggestion and your patch.
see https://www.debian.org/Bugs/Reporting

If Debian accepts this change, then Ubuntu will follow.

rosorio975 (rosorio975) said : #2

Manfred,

Thanks from your reply, I will follow-up to debian bug tracker.

regards,
-- rodrigo