>From 5b8a58981d5958dc882cab254bef7a3ecf8819a2 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 19 Jul 2015 14:55:05 -0700
Subject: [PATCH] Two rules can't take effect at the same time

* NEWS: Document this.
* zic.8: Document simultaneity constraints.
* zic.c (outzone): Check for two rules taking effect at the same time.
---
 NEWS  |  4 ++++
 zic.8 |  5 +++++
 zic.c | 10 ++++++++++
 3 files changed, 19 insertions(+)

diff --git a/NEWS b/NEWS
index da98b19..b7593e7 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,10 @@ Unreleased, experimental changes
     work in the default installation, they are not used in the data,
     and they are now considered obsolescent.
 
+    zic now checks that two rules don't take effect at the same time.
+    (Thanks to Jon Skeet and Arthur David Olson.)  Constraints on
+    simultaneity are now documented.
+
   Changes affecting installed data files
 
     Data entries have been simplified for Atlantic/Canary, Europe/Simferopol,
diff --git a/zic.8 b/zic.8
index fecedf8..dfb01db 100644
--- a/zic.8
+++ b/zic.8
@@ -381,6 +381,11 @@ Continuation lines may contain
 information, just as zone lines do, indicating that the next line is a further
 continuation.
 .PP
+If a zone changes at the same instant that a rule would otherwise take
+effect in the earlier zone or continuation line, the rule is ignored.
+In a single zone it is an error if two rules take effect at the same
+instant, or if two zone changes take effect at the same instant.
+.PP
 A link line has the form
 .sp
 .nf
diff --git a/zic.c b/zic.c
index bbcc4ef..96ab0e7 100644
--- a/zic.c
+++ b/zic.c
@@ -2375,6 +2375,16 @@ outzone(const struct zone * const zpfirst, const int zonecount)
 					if (k < 0 || jtime < ktime) {
 						k = j;
 						ktime = jtime;
+					} else if (jtime == ktime) {
+					  char const *dup_rules_msg =
+					    _("two rules for same instant");
+					  eats(zp->z_filename, zp->z_linenum,
+					       rp->r_filename, rp->r_linenum);
+					  warning(dup_rules_msg);
+					  rp = &zp->z_rules[k];
+					  eats(zp->z_filename, zp->z_linenum,
+					       rp->r_filename, rp->r_linenum);
+					  error(dup_rules_msg);
 					}
 				}
 				if (k < 0)
-- 
2.1.4

