aboutsummaryrefslogtreecommitdiff
path: root/unix/os/zgmtco.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/os/zgmtco.c')
-rw-r--r--unix/os/zgmtco.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/unix/os/zgmtco.c b/unix/os/zgmtco.c
new file mode 100644
index 00000000..03fa5db8
--- /dev/null
+++ b/unix/os/zgmtco.c
@@ -0,0 +1,49 @@
+/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <time.h>
+
+#define import_kernel
+#define import_knames
+#define import_spp
+#include <iraf.h>
+
+#define SECONDS_1970_TO_1980 315532800L
+
+
+/* ZGMTCO -- Return the correction, in seconds, from local standard time
+ * (clock time) to GMT. GMT = LST + gmtco (seconds), or gmtco = GMT-LST.
+ */
+int
+ZGMTCO (
+ XINT *gmtcor /* seconds */
+)
+{
+ time_t gmt_to_lst(), ltime;
+
+ /* Given an input value of zero (biased by SECONDS_1970_TO_1980)
+ * gmt_to_lst will return a negative value in seconds for a location
+ * in the US (as an limiting test case). We want to return the
+ * correction to LST to get GMT, a positive value for the US, so
+ * we need to negate this value. gmt_to_lst will already have taken
+ * daylight savings time into account. Although we talk about the
+ * US (as a test case) this relation will hold both east and west
+ * of Greenwich.
+ */
+
+ *gmtcor = -((XINT) gmt_to_lst ((time_t) SECONDS_1970_TO_1980));
+
+
+ /* Daylight saving time is not added to the output of gmt_to_lst()
+ * since it assumes Jan 1. Use the current date to determin if
+ * DST is in effect.
+ */
+
+ ltime = time(0);
+ if (localtime(&ltime)->tm_isdst)
+ *gmtcor = *gmtcor - 60L * 60L;
+
+ return (XOK);
+}