+
+ static void WriteZoneRules (TimeZoneInfo zone)
+ {
+ var rules = zone.GetAdjustmentRules ();
+ for (int i = 0; i < rules.Length; ++i) {
+ var rule = rules [i];
+ Console.WriteLine ();
+ Console.Write ("\tAdjustmentRules[{0,3}]: DaylightDelta={1}; DateStart={2:yyyy-MM}; DateEnd={3:yyyy-MM}; DaylightTransitionStart={4:D2}-{5:D2}T{6}; DaylightTransitionEnd={7:D2}-{8:D2}T{9}",
+ i,
+ rule.DaylightDelta,
+ rule.DateStart, rule.DateEnd,
+ rule.DaylightTransitionStart.Month, rule.DaylightTransitionStart.Day, rule.DaylightTransitionStart.TimeOfDay.TimeOfDay,
+ rule.DaylightTransitionEnd.Month, rule.DaylightTransitionEnd.Day, rule.DaylightTransitionEnd.TimeOfDay.TimeOfDay);
+ }
+ }
+
+ static void DumpTimeZoneFile (string path, DateTime? time)
+ {
+ var buffer = File.ReadAllBytes (path);
+ var zone = ParseTZBuffer (path, buffer, buffer.Length);
+ Console.Write ("Rules for: {0}", path);
+ WriteZoneRules (zone);
+ Console.WriteLine ();
+ if (time.HasValue) {
+ var offset = zone.GetUtcOffset (time.Value);
+ var isDst = zone.IsDaylightSavingTime (time.Value);
+ Console.WriteLine ("\tDate({0}): Offset({1}) IsDST({2})", time.Value, offset, isDst);
+ }
+ }
+#endif
+ }
+
+#if SELF_TEST
+ static string TimeZoneDataExportPath;
+#endif
+
+ internal static void DumpTimeZoneDataToFile (string id, byte[] buffer)
+ {
+#if SELF_TEST
+ int p = id.LastIndexOf ('/');
+ var o = Path.Combine (TimeZoneDataExportPath,
+ p >= 0 ? id.Substring (0, p) : id);
+ if (p >= 0)
+ o = Path.Combine (o, id.Substring (p+1));
+ Directory.CreateDirectory (Path.GetDirectoryName (o));
+ using (var f = File.OpenWrite (o))
+ f.Write (buffer, 0, buffer.Length);