Skip to content

Commit e57b6f8

Browse files
Mangemcmire
authored andcommitted
Show UTC timestamp in Time diffs when zone differs
This should help some people even more quickly see why the two dates are different moments in time as they won't have to do the offset calculation in their heads when they see the difference in hours/minutes and gmt_offset.
1 parent 2ad6284 commit e57b6f8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/super_diff/operational_sequencers/time_like.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ def self.applies_to?(expected, actual)
1414
protected
1515

1616
def attribute_names
17-
["year", "month", "day", "hour", "min", "sec", "nsec", "zone", "gmt_offset"]
17+
base = ["year", "month", "day", "hour", "min", "sec", "nsec", "zone", "gmt_offset"]
18+
19+
# If timezones are different, also show a normalized timestamp at the
20+
# end of the diff to help visualize why they are different moments in
21+
# time.
22+
if actual.zone != expected.zone
23+
base + ["utc"]
24+
else
25+
base
26+
end
1827
end
1928
end
2029
end

spec/integration/rspec/eq_matcher_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,10 @@
290290
plain_line " nsec: 0,"
291291
alpha_line "- zone: \"CET\","
292292
beta_line "+ zone: \"UTC\","
293-
alpha_line "- gmt_offset: 3600"
294-
beta_line "+ gmt_offset: 0"
293+
alpha_line "- gmt_offset: 3600,"
294+
beta_line "+ gmt_offset: 0,"
295+
alpha_line "- utc: 2011-12-13 15:15:16.000 UTC +00:00 (Time)"
296+
beta_line "+ utc: 2011-12-13 14:15:16.000 UTC +00:00 (Time)"
295297
plain_line " }>"
296298
},
297299
)

0 commit comments

Comments
 (0)