Пример #1
0
        private static int Main(string[] args)
        {
            Options options = new Options();
            ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error) { MutuallyExclusive = true });
            if (!parser.ParseArguments(args, options))
            {
                return 1;
            }

            List<DateTimeZone> zones = LoadSource(options);
            zones = zones.OrderBy(zone => zone.Id, StringComparer.Ordinal).ToList();

            if (options.ZoneId != null)
            {
                var zone = zones.FirstOrDefault(z => z.Id == options.ZoneId);
                if (zone == null)
                {
                    throw new Exception($"Unknown zone ID: {options.ZoneId}");
                }
                DumpZone(zone, options);
            }
            else
            {
                foreach (var zone in zones)
                {
                    DumpZone(zone, options);
                    Console.Write("\r\n");
                }
            }

            return 0;
        }
Пример #2
0
        private static int Main(string[] args)
        {
            Options options = new Options();
            ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error) { MutuallyExclusive = true });
            if (!parser.ParseArguments(args, options))
            {
                return 1;
            }
            TzdbDateTimeZoneSource source = LoadSource(options.Source);
            var dumper = new ZoneDumper(source, options);
            try
            {
                using (var writer = options.OutputFile == null ? Console.Out : File.CreateText(options.OutputFile))
                {
                    dumper.Dump(writer);
                }
            }
            catch (UserErrorException e)
            {
                Console.Error.WriteLine($"Error: {e.Message}");
                return 1;
            }

            return 0;
        }        
Пример #3
0
        // This will do something soon :)
        public IActionResult Generate(int startYear = 1, int endYear = 2035)
        {
            var source = TzdbDateTimeZoneSource.Default;
            var writer = new StringWriter();
            var options = new Options { FromYear = startYear, ToYear = endYear };
            var dumper = new ZoneDumper(source, options);
            dumper.Dump(writer);

            return new ContentResult
            {
                Content = writer.ToString(),
                ContentType = "text/plain",
                StatusCode = (int) HttpStatusCode.OK
            };
        }
Пример #4
0
 private static void DumpZone(DateTimeZone zone, Options options)
 {
     Console.Write("{0}\r\n", zone.Id);
     var initial = zone.GetZoneInterval(Instant.MinValue);
     Console.Write("Initially:           {0} {1} {2}\r\n",
         OffsetPattern.Format(initial.WallOffset),
         initial.Savings != Offset.Zero ? "daylight" : "standard",
         initial.Name);
     foreach (var zoneInterval in zone.GetZoneIntervals(options.Start, options.End)
         .Where(zi => zi.HasStart && zi.Start >= options.Start))
     {
         Console.Write("{0} {1} {2} {3}\r\n",
             InstantPattern.Format(zoneInterval.Start),
             OffsetPattern.Format(zoneInterval.WallOffset),
             zoneInterval.Savings != Offset.Zero ? "daylight" : "standard",
             zoneInterval.Name);
     }
 }
Пример #5
0
        private static int Main(string[] args)
        {
            Options options = new Options();
            ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error) { MutuallyExclusive = true });
            if (!parser.ParseArguments(args, options))
            {
                return 1;
            }

            List<DateTimeZone> zones = LoadSource(options.Source);
            zones = zones.OrderBy(zone => zone.Id, StringComparer.Ordinal).ToList();

            foreach (var zone in zones)
            {
                DumpZone(zone, options);
                Console.Write("\r\n");
            }

            return 0;
        }
Пример #6
0
 private static List<DateTimeZone> LoadSource(Options options)
 {
     var source = options.Source;
     if (source == null)
     {
         var provider = DateTimeZoneProviders.Tzdb;
         return provider.Ids.Select(id => provider[id]).ToList();
     }
     if (source.EndsWith(".nzd"))
     {
         var data = LoadFileOrUrl(source);
         var tzdbSource = TzdbDateTimeZoneSource.FromStream(new MemoryStream(data));
         return tzdbSource.GetIds().Select(id => tzdbSource.ForId(id)).ToList();
     }
     else
     {
         var compiler = new TzdbZoneInfoCompiler(log: null);
         var database = compiler.Compile(source);
         return database.GenerateDateTimeZones()
             .Concat(database.Aliases.Keys.Select(database.GenerateDateTimeZone))
             .ToList();
     }
 }
Пример #7
0
 public ZoneDumper(TzdbDateTimeZoneSource source, Options options)
 {
     this.source = source;
     this.options = options;
 }