1- // Copyright (c) 2024 TrakHound Inc., All Rights Reserved.
1+ // Copyright (c) 2025 TrakHound Inc., All Rights Reserved.
22// TrakHound Inc. licenses this file to you under the MIT license.
33
44using MTConnect . Agents . Metrics ;
@@ -47,6 +47,7 @@ public class MTConnectAgent : IMTConnectAgent, IDisposable
4747 private MTConnectAgentMetrics _metrics ;
4848 private readonly string _uuid ;
4949 private readonly ulong _instanceId ;
50+ private readonly TimeZoneInfo _timeZoneInfo ;
5051 private long _deviceModelChangeTime ;
5152 private Version _version ;
5253 private Version _mtconnectVersion ;
@@ -121,6 +122,11 @@ public string Sender
121122 }
122123 }
123124
125+ /// <summary>
126+ /// Get the TimeZone that is configured to Output
127+ /// </summary>
128+ public TimeZoneInfo TimeZoneOutput => _timeZoneInfo ;
129+
124130 /// <summary>
125131 /// A timestamp in 8601 format of the last update of the Device information for any device.
126132 /// </summary>
@@ -210,6 +216,7 @@ public MTConnectAgent(
210216 _deviceModelChangeTime = deviceModelChangeTime ;
211217 _mtconnectVersion = MTConnectVersions . Max ;
212218 _version = GetAgentVersion ( ) ;
219+ _timeZoneInfo = GetTimeZone ( _configuration ) ;
213220 InitializeAgentDevice ( initializeAgentDevice ) ;
214221 }
215222
@@ -228,6 +235,7 @@ public MTConnectAgent(
228235 _deviceModelChangeTime = deviceModelChangeTime ;
229236 _mtconnectVersion = _configuration != null && _configuration . DefaultVersion != null ? _configuration . DefaultVersion : MTConnectVersions . Max ;
230237 _version = GetAgentVersion ( ) ;
238+ _timeZoneInfo = GetTimeZone ( _configuration ) ;
231239 InitializeAgentDevice ( initializeAgentDevice ) ;
232240 }
233241
@@ -2288,5 +2296,26 @@ private static Version GetAgentVersion()
22882296 {
22892297 return Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version ;
22902298 }
2299+
2300+ private static TimeZoneInfo GetTimeZone ( IAgentConfiguration agentConfiguration )
2301+ {
2302+ if ( agentConfiguration != null )
2303+ {
2304+ if ( ! string . IsNullOrEmpty ( agentConfiguration . TimeZoneOutput ) )
2305+ {
2306+ var timeZoneDefinition = MTConnectTimeZone . Get ( agentConfiguration . TimeZoneOutput ) ;
2307+ if ( timeZoneDefinition != null )
2308+ {
2309+ var timeZoneInfo = timeZoneDefinition . ToTimeZoneInfo ( ) ;
2310+ if ( timeZoneInfo != null )
2311+ {
2312+ return timeZoneInfo ;
2313+ }
2314+ }
2315+ }
2316+ }
2317+
2318+ return TimeZoneInfo . Utc ;
2319+ }
22912320 }
22922321}
0 commit comments