< Summary

Information
Class: MyNet.Globalization.Facade.DateTimeExtensions
Assembly: MyNet.Globalization
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Globalization/Facade/Extensions/DateTimeExtensions.cs
Tag: 323_28699572109
Line coverage
0%
Covered lines: 0
Uncovered lines: 4
Coverable lines: 4
Total lines: 52
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToTimeZone(...)0%620%
IsTodayForTimeZone(...)100%210%
ToTimeZone(...)100%210%
ToCurrentTime(...)100%210%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Globalization/Facade/Extensions/DateTimeExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DateTimeExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using MyNet.Primitives;
 8using TimeOnly = System.TimeOnly;
 9using TimeZoneInfo = System.TimeZoneInfo;
 10
 11#pragma warning disable IDE0130 // Namespace does not match folder structure
 12namespace MyNet.Globalization.Facade;
 13#pragma warning restore IDE0130 // Namespace does not match folder structure
 14
 15public static class DateTimeExtensions
 16{
 17    extension(System.DateTime dateTime)
 18    {
 19        /// <summary>
 20        /// Converts the specified <see cref="DateTime"/> to the application's current time zone.
 21        /// </summary>
 22        /// <returns>The converted <see cref="DateTime"/> in the configured current time zone.</returns>
 023        public System.DateTime ToTimeZone(TimeZoneInfo? timeZone = null) => GlobalizationServices.Current.Convert(dateTi
 24
 25        /// <summary>
 26        /// Determines whether the specified <see cref="DateTime"/> falls on the current day in the application's curren
 27        /// </summary>
 28        /// <param name="timeZone">The time zone to use for the comparison. If null, the application's current time zone
 29        /// <returns>True if the specified <see cref="DateTime"/> falls on the current day in the specified or current t
 030        public bool IsTodayForTimeZone(TimeZoneInfo? timeZone = null) => dateTime.SameDay(dateTime.ToTimeZone(timeZone))
 31    }
 32
 33    extension(TimeOnly time)
 34    {
 35        /// <summary>
 36        /// Converts the given <see cref="DateTime"/> from a source time zone to a destination time zone.
 37        /// </summary>
 38        /// <param name="sourceTimeZone">The source time zone.</param>
 39        /// <param name="destinationTimeZone">The destination time zone.</param>
 40        /// <returns>The converted <see cref="TimeOnly"/> value.</returns>
 41        public TimeOnly ToTimeZone(TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
 042            => GlobalizationServices.Current.Convert(System.DateTime.UtcNow.ToTimeZone(sourceTimeZone).At(time), sourceT
 43
 44        /// <summary>
 45        /// Converts the given <see cref="DateTime"/> from a source time zone to the current time zone.
 46        /// </summary>
 47        /// <param name="sourceTimeZone">The source time zone.</param>
 48        /// <returns>The converted <see cref="System.TimeOnly"/> value.</returns>
 049        public TimeOnly ToCurrentTime(TimeZoneInfo sourceTimeZone) => time.ToTimeZone(sourceTimeZone, GlobalizationServi
 50    }
 51}
 52