This repository was archived by the owner on Sep 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathReplaceTimezone.cs
151 lines (147 loc) · 7.99 KB
/
ReplaceTimezone.cs
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Copyright 2012 Splunk, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"): you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
namespace Splunk
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/// <summary>
/// Parse timeszone strings.
/// </summary>
public static class ReplaceTimezone
{
/// <summary>
/// A list of timezone information, including nickname, UTC and full text.
/// This list distilled from various places on the web. Military timezones
/// are not represented.
/// </summary>
private static string[][] timeZones = new string[][]
{
// not order is important, if the nickname is part of a longer nickname
new string[] { "ACDT", "+1030", "Australian Central Daylight Time" },
new string[] { "ACST", "+0930", "Australian Central Standard Time" },
new string[] { "ADT", "-0300", "Atlantic Daylight Time" },
new string[] { "AEDT", "+1100", "Australian East Daylight Time" },
new string[] { "AEST", "+1000", "Australian East Standard Time" },
new string[] { "AHDT", "-0900", "Alaska-Hawaii Daylight Time" },
new string[] { "AHST", "-1000", "Alaska-Hawaii Standard Time" },
new string[] { "AST", "-0400", "Atlantic Standard Time" },
new string[] { "AT", "-0200", "Azores" },
new string[] { "AWDT", "+0900", "Australian West Daylight Time" },
new string[] { "AWST", "+0800", "Australian West Standard Time" },
new string[] { "BAT", "+0300", "Bhagdad" },
new string[] { "BDST", "+0200", "British Double Summer" },
new string[] { "BET", "-1100", "Bering Standard Time" },
new string[] { "BST", "-0300", "Brazil Standard Time" },
new string[] { "BT", "+0300", "Baghdad" },
new string[] { "BZT2", "-0300", "Brazil Zone 2" },
new string[] { "CADT", "+1030", "Central Australian Daylight Time" },
new string[] { "CAST", "+0930", "Central Australian Standard Time" },
new string[] { "CAT", "-1000", "Central Alaska" },
new string[] { "CCT", "+0800", "China Coast" },
new string[] { "CDT", "-0500", "Central Daylight Time" },
new string[] { "CED", "+0200", "Central European Daylight Time" },
new string[] { "CET", "+0100", "Central European" },
new string[] { "CST", "-0600", "Central Standard Time" },
new string[] { "CENTRAL", "-0600", "Central Standard Time" },
new string[] { "EAST", "+1000", "Eastern Australian Standard Time" },
new string[] { "EDT", "-0400", "Eastern Daylight Time" },
new string[] { "EED", "+0300", "Eastern European Daylight Time" },
new string[] { "EET", "+0200", "Eastern Europe" },
new string[] { "EEST", "+0300", "Eastern Europe Summer" },
new string[] { "EST", "-0500", "Eastern Standard Time" },
new string[] { "EASTERN", "-0500", "Eastern Standard Time" },
new string[] { "FST", "+0200", "French Summer" },
new string[] { "FWT", "+0100", "French Winter" },
new string[] { "GMT", "-0000", "Greenwich Mean" },
new string[] { "GST", "+1000", "Guam Standard Time" },
new string[] { "HDT", "-0900", "Hawaii Daylight Time" },
new string[] { "HST", "-1000", "Hawaii Standard Time" },
new string[] { "IDLE", "+1200", "Internation Date Line East" },
new string[] { "IDLW", "-1200", "Internation Date Line West" },
new string[] { "IST", "+0530", "Indian Standard Time" },
new string[] { "IT", "+0330", "Iran" },
new string[] { "JST", "+0900", "Japan Standard Time" },
new string[] { "JT", "+0700", "Java" },
new string[] { "MDT", "-0600", "Mountain Daylight Time" },
new string[] { "MED", "+0200", "Middle European Daylight Time" },
new string[] { "MET", "+0100", "Middle European" },
new string[] { "MEST", "+0200", "Middle European Summer" },
new string[] { "MEWT", "+0100", "Middle European Winter" },
new string[] { "MST", "-0700", "Mountain Standard Time" },
new string[] { "MOUNTAIN", "-0700", "Mountain Standard Time" },
new string[] { "MT", "+0800", "Moluccas" },
new string[] { "NDT", "-0230", "Newfoundland Daylight Time" },
new string[] { "NFT", "-0330", "Newfoundland" },
new string[] { "NT", "-1100", "Nome" },
new string[] { "NST", "+0630", "North Sumatra" },
new string[] { "NZST", "+1200", "New Zealand Standard Time" },
new string[] { "NZDT", "+1300", "New Zealand Daylight Time " },
new string[] { "NZT", "+1200", "New Zealand" },
new string[] { "NZ", "+1100", "New Zealand " },
new string[] { "PDT", "-0700", "Pacific Daylight Time" },
new string[] { "PST", "-0800", "Pacific Standard Time" },
new string[] { "PACIFIC", "-0800", "Pacific Standard Time" },
new string[] { "ROK", "+0900", "Republic of Korea" },
new string[] { "SAD", "+1000", "South Australia Daylight Time" },
new string[] { "SAST", "+0900", "South Australia Standard Time" },
new string[] { "SAT", "+0900", "South Australia Standard Time" },
new string[] { "SDT", "+1000", "South Australia Daylight Time" },
new string[] { "SST", "+0200", "Swedish Summer" },
new string[] { "SWT", "+0100", "Swedish Winter" },
new string[] { "USZ3", "+0400", "USSR Zone 3" },
new string[] { "USZ4", "+0500", "USSR Zone 4" },
new string[] { "USZ5", "+0600", "USSR Zone 5" },
new string[] { "USZ6", "+0700", "USSR Zone 6" },
new string[] { "UTC", "-0000", "Universal Coordinated" },
new string[] { "UT", "-0000", "Universal Coordinated" },
new string[] { "UZ10", "+1100", "USSR Zone 10" },
new string[] { "WAT", "-0100", "West Africa" },
new string[] { "WET", "-0000", "West European" },
new string[] { "WST", "+0800", "West Australian Standard Time" },
new string[] { "YDT", "-0800", "Yukon Daylight Time" },
new string[] { "YST", "-0900", "Yukon Standard Time" },
new string[] { "ZP4", "+0400", "USSR Zone 3" },
new string[] { "ZP5", "+0500", "USSR Zone 4" },
new string[] { "ZP6", "+0600", "USSR Zone 5" }
};
/// <summary>
/// Returns the date with the textual timezone replaced with
/// the UTC equivalent, if found.
/// </summary>
/// <param name="date">The date</param>
/// <returns>The date with timezone string</returns>
public static string ReplaceTimeZone(string date)
{
foreach (string[] timezone in timeZones)
{
// look for pretty text first
if (date.Contains(timezone[2]))
{
date = date.Replace(timezone[2], timezone[1]);
break;
}
else if (date.Contains(timezone[0]))
{
date = date.Replace(timezone[0], timezone[1]);
break;
}
}
return date;
}
}
}