SIPSorcery.AppServer.DialPlan.DialPlanSettings.GetTimezoneOffset C# (CSharp) 메소드

GetTimezoneOffset() 공개 메소드

If set retrieves the user's UTC time zone offset for use in the dialplan.
public GetTimezoneOffset ( ) : int
리턴 int
        public int GetTimezoneOffset()
        {
            if (Options != null && !Options.Timezone.IsNullOrBlank())
            {
                foreach (TimeZoneInfo timezone in TimeZoneInfo.GetSystemTimeZones())
                {
                    if (timezone.DisplayName == Options.Timezone)
                    {
                        return (int)timezone.GetUtcOffset(DateTimeOffset.UtcNow).TotalMinutes;
                    }
                }
            }

            return 0;
        }

Usage Example

        public void ExtractTimezoneOffsetTest()
        {
            SIPDialplanOption options = new SIPDialplanOption()
            {
                timezone = "(UTC+10:00) Hobart"
            };

            DialPlanSettings settings = new DialPlanSettings(null, null, null, options);

            int timezoneOffset = settings.GetTimezoneOffset();

            Assert.IsTrue(timezoneOffset >= 600 && timezoneOffset <= 660, "The timezone offset extracted was incorrect.");
        }