Skip to content

Commit 4b6fc5c

Browse files
niyariveler
andauthored
Updated Unix Timestamp Converter (#509)
* Add string keywords. * Update TimestampTool * Add info text. * Update UI * Add string keywords. (/*/Timestamp.resw) * Fix UI * Add TimestampToolHelper. * Update TimestampTool * Update Timestamp.resw * Cleanup file. * Added CardStyle. * Stack UI * Fix UI * Revert to e45d522. (Timezone info: 509#issuecomment-1126643640 ) * Changed UI. Content display by window width. * Preparation for Conflict Resolution. * Removed compact DateTime info. * Code cleanup #discussion_r874407747 * Changed the clipboard datetime string recognition process. * Added summary. * Fix types. * Fixed Page.Resources. * Change names. * Remove Strings.CurrentDateTimeTitle * Change names. * Added comment. Co-authored-by: Etienne BAUDOUX <[email protected]>
1 parent e9e5f97 commit 4b6fc5c

File tree

23 files changed

+1119
-492
lines changed

23 files changed

+1119
-492
lines changed

src/dev/impl/DevToys/DevToys.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<Compile Include="Helpers\HashingHelper.cs" />
3737
<Compile Include="Helpers\NumberBaseHelper.cs" />
3838
<Compile Include="Helpers\StringManipulationHelper.cs" />
39+
<Compile Include="Helpers\TimestampToolHelper.cs" />
3940
<Compile Include="Helpers\XmlHelper.cs" />
4041
<Compile Include="Helpers\SqlFormatter\Core\Formatter.cs" />
4142
<Compile Include="Helpers\SqlFormatter\Core\Indentation.cs" />
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#nullable enable
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Collections.ObjectModel;
6+
using System.Linq;
7+
using System.Text.RegularExpressions;
8+
9+
namespace DevToys.Helpers
10+
{
11+
internal static class TimestampToolHelper
12+
{
13+
internal static class ZoneInfo
14+
{
15+
private static string _utcDisplayName = "";
16+
private static string _localDisplayName = "";
17+
private static readonly IReadOnlyCollection<TimeZoneInfo> _systemTimeZone = TimeZoneInfo.GetSystemTimeZones();
18+
private static readonly IReadOnlyDictionary<string, string> _timeZoneCollection = InitTimeZoneCollection();
19+
20+
internal static string UtcDisplayName => _utcDisplayName;
21+
22+
internal static string LocalDisplayName => _localDisplayName;
23+
24+
internal static IReadOnlyList<string> DisplayNames => _timeZoneCollection.Keys.ToList();
25+
26+
internal static IReadOnlyDictionary<string, string> TimeZones => _timeZoneCollection;
27+
28+
private static IReadOnlyDictionary<string, string> InitTimeZoneCollection()
29+
{
30+
Dictionary<string, string> timeZoneCollection = new();
31+
if (!Regex.IsMatch(_systemTimeZone.ElementAt(0).DisplayName, @"^\(UTC.*\).+$"))
32+
{
33+
// version < .Net6
34+
// This implementation mitigates the changes in the strings
35+
// that are obtained when optimized in release builds,
36+
// as the target of external tools is .net6 or earlier.
37+
// zone.DisplayName : "(UTC+09:00) 大阪、札幌、東京"( >= .net6) or "東京 (標準時)"( < .net6)
38+
foreach (TimeZoneInfo zone in _systemTimeZone)
39+
{
40+
string displayName = $"(UTC{zone.BaseUtcOffset.Hours:+00;-00;}:{zone.BaseUtcOffset.Minutes:00;00;}) " + zone.DisplayName;
41+
if (zone.Id == TimeZoneInfo.Utc.Id)
42+
{
43+
displayName = "(UTC) " + zone.DisplayName;
44+
_utcDisplayName = "(UTC) " + zone.DisplayName;
45+
}
46+
if (zone.Id == TimeZoneInfo.Local.Id)
47+
{
48+
_localDisplayName = displayName;
49+
}
50+
timeZoneCollection.Add(displayName, zone.Id);
51+
}
52+
}
53+
else
54+
{
55+
// version >= .Net6
56+
foreach (TimeZoneInfo zone in _systemTimeZone)
57+
{
58+
timeZoneCollection.Add(zone.DisplayName, zone.Id);
59+
}
60+
_utcDisplayName = TimeZoneInfo.Utc.DisplayName;
61+
_localDisplayName = TimeZoneInfo.Local.DisplayName;
62+
}
63+
return timeZoneCollection;
64+
}
65+
}
66+
67+
internal static class TimeZone
68+
{
69+
internal static DateTimeOffset SafeMinValue(TimeZoneInfo timezone)
70+
{
71+
if (timezone is null)
72+
{
73+
timezone = TimeZoneInfo.Utc;
74+
}
75+
DateTimeOffset t1 = TimeZoneInfo.ConvertTime(
76+
new DateTimeOffset(10, 1, 1, 0, 0, 0, TimeZoneInfo.Utc.BaseUtcOffset),
77+
timezone);
78+
DateTimeOffset minValue = DateTimeOffset.MinValue;
79+
if (t1.Year < 10)
80+
{
81+
minValue = minValue.Subtract(t1.Offset);
82+
}
83+
return TimeZoneInfo.ConvertTime(minValue, timezone);
84+
}
85+
86+
internal static DateTimeOffset SafeMaxValue(TimeZoneInfo timezone)
87+
{
88+
if (timezone is null)
89+
{
90+
timezone = TimeZoneInfo.Utc;
91+
}
92+
DateTimeOffset t1 = TimeZoneInfo.ConvertTime(
93+
new DateTimeOffset(9990, 12, 31, 23, 59, 59, TimeZoneInfo.Utc.BaseUtcOffset),
94+
timezone);
95+
DateTimeOffset maxValue = DateTimeOffset.MaxValue;
96+
if (t1.Year > 9990)
97+
{
98+
maxValue = maxValue.Subtract(t1.Offset);
99+
}
100+
return TimeZoneInfo.ConvertTime(maxValue, timezone);
101+
}
102+
103+
}
104+
105+
}
106+
}

src/dev/impl/DevToys/LanguageManager.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,6 +2731,16 @@ public class TimestampStrings : ObservableObject
27312731
/// </summary>
27322732
public string AccessibleName => _resources.GetString("AccessibleName");
27332733

2734+
/// <summary>
2735+
/// Gets the resource TimeZoneTitle.
2736+
/// </summary>
2737+
public string TimeZoneTitle => _resources.GetString("TimeZoneTitle");
2738+
2739+
/// <summary>
2740+
/// Gets the resource DaylightSavingTime.
2741+
/// </summary>
2742+
public string DaylightSavingTime => _resources.GetString("DaylightSavingTime");
2743+
27342744
/// <summary>
27352745
/// Gets the resource DayTitle.
27362746
/// </summary>
@@ -2741,6 +2751,16 @@ public class TimestampStrings : ObservableObject
27412751
/// </summary>
27422752
public string Description => _resources.GetString("Description");
27432753

2754+
/// <summary>
2755+
/// Gets the resource DisabledDaylightSavingTime.
2756+
/// </summary>
2757+
public string DisabledDaylightSavingTime => _resources.GetString("DisabledDaylightSavingTime");
2758+
2759+
/// <summary>
2760+
/// Gets the resource DSTAmbiguousTime.
2761+
/// </summary>
2762+
public string DSTAmbiguousTime => _resources.GetString("DSTAmbiguousTime");
2763+
27442764
/// <summary>
27452765
/// Gets the resource HourTitle.
27462766
/// </summary>
@@ -2771,6 +2791,11 @@ public class TimestampStrings : ObservableObject
27712791
/// </summary>
27722792
public string MonthTitle => _resources.GetString("MonthTitle");
27732793

2794+
/// <summary>
2795+
/// Gets the resource OffsetTitle.
2796+
/// </summary>
2797+
public string OffsetTitle => _resources.GetString("OffsetTitle");
2798+
27742799
/// <summary>
27752800
/// Gets the resource SearchDisplayName.
27762801
/// </summary>
@@ -2786,6 +2811,11 @@ public class TimestampStrings : ObservableObject
27862811
/// </summary>
27872812
public string SecondsTitle => _resources.GetString("SecondsTitle");
27882813

2814+
/// <summary>
2815+
/// Gets the resource SupportsDaylightSavingTime.
2816+
/// </summary>
2817+
public string SupportsDaylightSavingTime => _resources.GetString("SupportsDaylightSavingTime");
2818+
27892819
/// <summary>
27902820
/// Gets the resource TimestampTitle.
27912821
/// </summary>
@@ -2796,6 +2826,11 @@ public class TimestampStrings : ObservableObject
27962826
/// </summary>
27972827
public string UTCDateTime => _resources.GetString("UTCDateTime");
27982828

2829+
/// <summary>
2830+
/// Gets the resource UtcTicksTitle.
2831+
/// </summary>
2832+
public string UtcTicksTitle => _resources.GetString("UtcTicksTitle");
2833+
27992834
/// <summary>
28002835
/// Gets the resource YearTitle.
28012836
/// </summary>

src/dev/impl/DevToys/Strings/cs-CZ/Timestamp.resw

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,24 @@
120120
<data name="AccessibleName" xml:space="preserve">
121121
<value>Timestamp converter tool</value>
122122
</data>
123+
<data name="TimeZoneTitle" xml:space="preserve">
124+
<value>Time zone</value>
125+
</data>
126+
<data name="DaylightSavingTime" xml:space="preserve">
127+
<value>Daylight saving time.</value>
128+
</data>
123129
<data name="DayTitle" xml:space="preserve">
124130
<value>Day</value>
125131
</data>
126132
<data name="Description" xml:space="preserve">
127133
<value>Convert timestamp to human-readable date and vice versa</value>
128134
</data>
135+
<data name="DisabledDaylightSavingTime" xml:space="preserve">
136+
<value>There is no daylight saving time.</value>
137+
</data>
138+
<data name="DSTAmbiguousTime" xml:space="preserve">
139+
<value>DST Ambiguous time.</value>
140+
</data>
129141
<data name="HourTitle" xml:space="preserve">
130142
<value>Hour (24 hour)</value>
131143
</data>
@@ -144,6 +156,9 @@
144156
<data name="MonthTitle" xml:space="preserve">
145157
<value>Month</value>
146158
</data>
159+
<data name="OffsetTitle" xml:space="preserve">
160+
<value>Offset</value>
161+
</data>
147162
<data name="SearchDisplayName" xml:space="preserve">
148163
<value>Unix Timestamp Converter</value>
149164
</data>
@@ -154,12 +169,18 @@
154169
<data name="SecondsTitle" xml:space="preserve">
155170
<value>Seconds</value>
156171
</data>
172+
<data name="SupportsDaylightSavingTime" xml:space="preserve">
173+
<value>There is daylight saving time.</value>
174+
</data>
157175
<data name="TimestampTitle" xml:space="preserve">
158176
<value>Timestamp</value>
159177
</data>
160178
<data name="UTCDateTime" xml:space="preserve">
161179
<value>UTC Date and Time</value>
162180
</data>
181+
<data name="UtcTicksTitle" xml:space="preserve">
182+
<value>UtcTicks</value>
183+
</data>
163184
<data name="YearTitle" xml:space="preserve">
164185
<value>Year</value>
165186
</data>

src/dev/impl/DevToys/Strings/de-DE/Timestamp.resw

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,24 @@
120120
<data name="AccessibleName" xml:space="preserve">
121121
<value>Timestamp converter tool</value>
122122
</data>
123+
<data name="TimeZoneTitle" xml:space="preserve">
124+
<value>Time zone</value>
125+
</data>
126+
<data name="DaylightSavingTime" xml:space="preserve">
127+
<value>Daylight saving time.</value>
128+
</data>
123129
<data name="DayTitle" xml:space="preserve">
124130
<value>Day</value>
125131
</data>
126132
<data name="Description" xml:space="preserve">
127133
<value>Convert timestamp to human-readable date and vice versa</value>
128134
</data>
135+
<data name="DisabledDaylightSavingTime" xml:space="preserve">
136+
<value>There is no daylight saving time.</value>
137+
</data>
138+
<data name="DSTAmbiguousTime" xml:space="preserve">
139+
<value>DST Ambiguous time.</value>
140+
</data>
129141
<data name="HourTitle" xml:space="preserve">
130142
<value>Hour (24 hour)</value>
131143
</data>
@@ -144,6 +156,9 @@
144156
<data name="MonthTitle" xml:space="preserve">
145157
<value>Month</value>
146158
</data>
159+
<data name="OffsetTitle" xml:space="preserve">
160+
<value>Offset</value>
161+
</data>
147162
<data name="SearchDisplayName" xml:space="preserve">
148163
<value>Unix Timestamp Converter</value>
149164
</data>
@@ -154,12 +169,18 @@
154169
<data name="SecondsTitle" xml:space="preserve">
155170
<value>Seconds</value>
156171
</data>
172+
<data name="SupportsDaylightSavingTime" xml:space="preserve">
173+
<value>There is daylight saving time.</value>
174+
</data>
157175
<data name="TimestampTitle" xml:space="preserve">
158176
<value>Timestamp</value>
159177
</data>
160178
<data name="UTCDateTime" xml:space="preserve">
161179
<value>UTC Date and Time</value>
162180
</data>
181+
<data name="UtcTicksTitle" xml:space="preserve">
182+
<value>UtcTicks</value>
183+
</data>
163184
<data name="YearTitle" xml:space="preserve">
164185
<value>Year</value>
165186
</data>

src/dev/impl/DevToys/Strings/en-US/Timestamp.resw

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,24 @@
120120
<data name="AccessibleName" xml:space="preserve">
121121
<value>Timestamp converter tool</value>
122122
</data>
123+
<data name="TimeZoneTitle" xml:space="preserve">
124+
<value>Time zone</value>
125+
</data>
126+
<data name="DaylightSavingTime" xml:space="preserve">
127+
<value>Daylight saving time.</value>
128+
</data>
123129
<data name="DayTitle" xml:space="preserve">
124130
<value>Day</value>
125131
</data>
126132
<data name="Description" xml:space="preserve">
127133
<value>Convert timestamp to human-readable date and vice versa</value>
128134
</data>
135+
<data name="DisabledDaylightSavingTime" xml:space="preserve">
136+
<value>There is no daylight saving time.</value>
137+
</data>
138+
<data name="DSTAmbiguousTime" xml:space="preserve">
139+
<value>DST Ambiguous time.</value>
140+
</data>
129141
<data name="HourTitle" xml:space="preserve">
130142
<value>Hour (24 hour)</value>
131143
</data>
@@ -144,6 +156,9 @@
144156
<data name="MonthTitle" xml:space="preserve">
145157
<value>Month</value>
146158
</data>
159+
<data name="OffsetTitle" xml:space="preserve">
160+
<value>Offset</value>
161+
</data>
147162
<data name="SearchDisplayName" xml:space="preserve">
148163
<value>Unix Timestamp Converter</value>
149164
</data>
@@ -154,12 +169,18 @@
154169
<data name="SecondsTitle" xml:space="preserve">
155170
<value>Seconds</value>
156171
</data>
172+
<data name="SupportsDaylightSavingTime" xml:space="preserve">
173+
<value>There is daylight saving time.</value>
174+
</data>
157175
<data name="TimestampTitle" xml:space="preserve">
158176
<value>Timestamp</value>
159177
</data>
160178
<data name="UTCDateTime" xml:space="preserve">
161179
<value>UTC Date and Time</value>
162180
</data>
181+
<data name="UtcTicksTitle" xml:space="preserve">
182+
<value>UtcTicks</value>
183+
</data>
163184
<data name="YearTitle" xml:space="preserve">
164185
<value>Year</value>
165186
</data>

0 commit comments

Comments
 (0)