-
Notifications
You must be signed in to change notification settings - Fork 131
/
GenerateFlipItTimeZoneCities.linq
59 lines (49 loc) · 1.54 KB
/
GenerateFlipItTimeZoneCities.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<Query Kind="Program">
<DisableMyExtensions>true</DisableMyExtensions>
</Query>
void Main()
{
var timeZones = new List<TimeZone>();
var xml = XDocument.Load(@"C:\dev\FlipIt other\windowsZones.xml");
var version = xml.Descendants("mapTimezones").Attributes("typeVersion").First().Value;
var mapZoneElements = from c in xml.Root.Descendants("mapZone")
select c;
foreach (var e in mapZoneElements)
{
var timeZoneID = e.Attribute("other").Value;
var timeZone = timeZones.SingleOrDefault(t => t.TimeZoneID == timeZoneID);
if (timeZone == null)
{
timeZone = new TimeZone {TimeZoneID = timeZoneID };
timeZones.Add(timeZone);
}
var typeAttribute = e.Attribute("type").Value;
var potentialNames = typeAttribute.Split(" ");
foreach (var potentialName in potentialNames)
{
var name = CleanName(potentialName);
if (!timeZone.Cities.Contains(name))
{
timeZone.Cities.Add(name);
}
}
}
Console.WriteLine($"; Generated by GenerateFlipItTimeZoneCities.linq using https://github.com/unicode-org/cldr/blob/master/common/supplemental/windowsZones.xml version {version}");
foreach (var timeZone in timeZones)
{
Console.WriteLine($"{timeZone.TimeZoneID}={String.Join(',', timeZone.Cities)}");
}
}
string CleanName(string s)
{
var i = s.LastIndexOf('/');
if (i == -1)
return s;
return s.Substring(i+1).Replace('_', ' ');
}
class TimeZone
{
public string TimeZoneID { get; set; }
public List<string> Cities { get; } = new List<string>();
}
// You can define other methods, fields, classes and namespaces here