IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
TimeZone.cs
Go to the documentation of this file.
1using System;
2using System.IO;
3
4using IKVM.Runtime;
5
7{
8
12 static class TimeZone
13 {
14
19 static string GetCurrentTimeZoneID()
20 {
21 return TimeZoneInfo.Local.Id;
22 }
23
30 static string MatchJavaTZ(string javaHome, string tzName)
31 {
32 try
33 {
34 var mapFileName = Path.Combine(javaHome, "lib", "tzmappings");
35 if (File.Exists(mapFileName) == false)
36 return null;
37
38 using var mapFile = File.OpenText(mapFileName);
39 string mapLine = null;
40 while ((mapLine = mapFile.ReadLine()) != null)
41 {
42 mapLine = mapLine.Trim();
43 if (mapLine.Length < 4)
44 continue;
45 if (mapLine[0] == '#')
46 continue;
47
48 var l = mapLine.Split(':');
49 if (l.Length < 4)
50 continue;
51
52 if (l[0] == tzName)
53 return l[3];
54 }
55
56 return null;
57 }
58 catch (IOException)
59 {
60 return null;
61 }
62 }
63
69 public static string getSystemTimeZoneID(string javaHome)
70 {
72 return MatchJavaTZ(javaHome, GetCurrentTimeZoneID()) ?? getSystemGMTOffsetID();
73 else
74 return GetCurrentTimeZoneID() ?? getSystemGMTOffsetID();
75 }
76
81 public static string getSystemGMTOffsetID()
82 {
83 var sp = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);
84 var h = sp.Hours;
85 var m = sp.Minutes;
86 if (h == 0 && m == 0)
87 return "GMT";
88 else if (h >= 0 && m >= 0)
89 return $"GMT+{h:D2}:{m:D2}";
90 else
91 return $"GMT-{-h:D2}:{-m:D2}";
92 }
93
94 }
95
96}
Implements the native methods for 'java.util.TimeZone'.
Definition TimeZone.cs:13
static string getSystemTimeZoneID(string javaHome)
Implements the native method 'getSystemTimeZoneID'.
Definition TimeZone.cs:69
static string getSystemGMTOffsetID()
Implements the native method 'getSystemGMTOffsetID'.
Definition TimeZone.cs:81
Maintains various information about the current runtime environment.
static bool IsWindows
Returns true if the current platform is Windows.