コード例 #1
0
 private string GetTimeZoneName()
 {
     if (_timeZone.StandardName == "Etc/UTC")
     {
         return(CoordinatedUniversalTime);
     }
     TZConvert.TryWindowsToIana(_timeZone.StandardName, out var value);
     return(value);
 }
コード例 #2
0
ファイル: TimeZoneManager.cs プロジェクト: Furtif/Ryujinx
        private void InitializeLocationNameCache()
        {
            if (HasTimeZoneBinaryTitle())
            {
                using (IStorage ncaFileStream = new LocalStorage(_device.FileSystem.SwitchPathToSystemPath(GetTimeZoneBinaryTitleContentPath()), FileAccess.Read, FileMode.Open))
                {
                    Nca         nca              = new Nca(_device.System.KeySet, ncaFileStream);
                    IFileSystem romfs            = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
                    Stream      binaryListStream = romfs.OpenFile("binaryList.txt", OpenMode.Read).AsStream();

                    StreamReader reader = new StreamReader(binaryListStream);

                    List <string> locationNameList = new List <string>();

                    string locationName;
                    while ((locationName = reader.ReadLine()) != null)
                    {
                        locationNameList.Add(locationName);
                    }

                    _locationNameCache = locationNameList.ToArray();
                }
            }
            else
            {
                ReadOnlyCollection <TimeZoneInfo> timeZoneInfos = TimeZoneInfo.GetSystemTimeZones();
                _locationNameCache = new string[timeZoneInfos.Count];

                int i = 0;

                foreach (TimeZoneInfo timeZoneInfo in timeZoneInfos)
                {
                    bool needConversion = TZConvert.TryWindowsToIana(timeZoneInfo.Id, out string convertedName);
                    if (needConversion)
                    {
                        _locationNameCache[i] = convertedName;
                    }
                    else
                    {
                        _locationNameCache[i] = timeZoneInfo.Id;
                    }
                    i++;
                }

                // As we aren't using the system archive, "UTC" might not exist on the host system.
                // Load from C# TimeZone APIs UTC id.
                string utcId             = TimeZoneInfo.Utc.Id;
                bool   utcNeedConversion = TZConvert.TryWindowsToIana(utcId, out string utcConvertedName);
                if (utcNeedConversion)
                {
                    utcId = utcConvertedName;
                }

                _deviceLocationName = utcId;
            }
        }
コード例 #3
0
        public void Can_Convert_Windows_Zones_To_Iana_Golden_Zones()
        {
            var errors       = 0;
            var windowsZones = TZConvert.KnownWindowsTimeZoneIds;

            foreach (var windowsZone in windowsZones)
            {
                if (TZConvert.TryWindowsToIana(windowsZone, out var ianaZone))
                {
                    Assert.NotNull(ianaZone);
                    Assert.NotEqual(string.Empty, ianaZone);
                }
                else
                {
                    errors++;
                    _output.WriteLine($"Failed to convert \"{windowsZone}\"");
                }
            }

            Assert.Equal(0, errors);
        }
コード例 #4
0
        public void Can_Convert_Windows_System_Zones_To_Iana()
        {
            Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "OS is not Windows.");

            var errors = 0;
            IEnumerable <string> windowsZones = TimeZoneInfo.GetSystemTimeZones().Select(x => x.Id);

            foreach (string windowsZone in windowsZones)
            {
                if (TZConvert.TryWindowsToIana(windowsZone, out string ianaZone))
                {
                    Assert.NotNull(ianaZone);
                    Assert.NotEqual(string.Empty, ianaZone);
                }
                else
                {
                    errors++;
                    _output.WriteLine($"Failed to convert \"{windowsZone}\"");
                }
            }

            Assert.Equal(0, errors);
        }
コード例 #5
0
        /// <summary>
        /// Maps the internal employee availability model back to Teams availability items.
        /// </summary>
        /// <param name="availabilityModel">The model to map.</param>
        /// <param name="timeZoneInfoId">The time zone id to use to convert utc back to local.</param>
        /// <returns>The list of Teams availability items.</returns>
        public IList <AvailabilityItem> MapAvailability(EmployeeAvailabilityModel availabilityModel)
        {
            // when writing availability to Teams, we need to use IANA time zones rather than
            // Windows, so convert if necessary
            if (!TZConvert.TryWindowsToIana(availabilityModel.TimeZoneInfoId, out string ianaTimeZone))
            {
                ianaTimeZone = availabilityModel.TimeZoneInfoId;
            }

            // Some WFM providers allow for availability to be different for different weeks on an
            // alternating basis, however, Teams only allows a single 'current' availability pattern
            // to be defined per user this means that we need to identify the item in the rotational
            // availability that represents the current week.
            var rotationalWeekNumber = (((int)((_timeService.UtcNow - availabilityModel.CycleBaseDate).TotalDays / 7)) % availabilityModel.NumberOfWeeks) + 1;

            var groupedByDayItems = availabilityModel.Availability
                                    .Where(a => a.WeekNumber == rotationalWeekNumber)
                                    .GroupBy(a => a.DayOfWeek.ToString(), a => new TimeSlotItem {
                StartTime = a.StartTime, EndTime = a.EndTime
            }, (key, g) =>
                                             new
            {
                Day       = key,
                TimeSlots = g.ToList()
            });

            var availabilityItems = new List <AvailabilityItem>();

            foreach (var item in groupedByDayItems)
            {
                var availabilityItem = new AvailabilityItem
                {
                    Recurrence = new RecurrenceItem
                    {
                        Pattern = new PatternItem
                        {
                            DaysOfWeek = new List <string> {
                                item.Day
                            },
                            Interval = 1,
                            Type     = "Weekly"
                        },
                        Range = new RangeItem
                        {
                            Type = "noEnd"
                        }
                    },
                    TimeSlots = new List <TimeSlotItem>(),
                    TimeZone  = ianaTimeZone
                };

                foreach (var timeSlot in item.TimeSlots)
                {
                    availabilityItem.TimeSlots.Add(new TimeSlotItem
                    {
                        StartTime = DateTimeHelper.ConvertToLocalTime(timeSlot.StartTime, availabilityModel.TimeZoneInfoId, _timeService),
                        EndTime   = DateTimeHelper.ConvertToLocalTime(timeSlot.EndTime, availabilityModel.TimeZoneInfoId, _timeService)
                    });
                }

                availabilityItems.Add(availabilityItem);
            }

            if (availabilityItems.Count < 7)
            {
                AddUnavailableDays(availabilityItems, ianaTimeZone);
            }

            return(availabilityItems);
        }
コード例 #6
0
 private static void Initialize()
 {
     lock (typeof(IntlContext)) {
         bool isTimeZoneAutoDetected = defaultTimeZone == null;
         if (defaultTimeZone == null)
         {
             TimeZoneInfo localTimeZone = TimeZoneInfo.Local;
             if (IntlUtility.IsValidTimeZoneName(localTimeZone.Id))
             {
                 defaultTimeZone = IntlUtility.CanonicalizeTimeZoneName(localTimeZone.Id);
             }
             else
             {
                 if (Environment.OSVersion.Platform != PlatformID.Unix && TZConvert.TryWindowsToIana(localTimeZone.StandardName, out string result))
                 {
                     defaultTimeZone = IntlUtility.CanonicalizeTimeZoneName(result);
                 }
                 if (defaultTimeZone == null)
                 {
                     TimeZoneInfo[] systemIanaTimezones = TimeZoneInfo.GetSystemTimeZones().Where(v => IntlUtility.IsValidTimeZoneName(v.Id)).ToArray();
                     TimeZoneInfo   matched             = systemIanaTimezones.FirstOrDefault(v => v.HasSameRules(localTimeZone)) ?? systemIanaTimezones.FirstOrDefault(v => v.BaseUtcOffset == localTimeZone.BaseUtcOffset);
                     if (matched != null)
                     {
                         defaultTimeZone = IntlUtility.CanonicalizeTimeZoneName(matched.Id);
                     }
                 }
             }
             if (defaultTimeZone == null)
             {
                 defaultTimeZone = "UTC";
             }
         }
         if (regionCode == null)
         {
             regionCode = RegionInfo.CurrentRegion.TwoLetterISORegionName;
             if (regionCode == "IV")
             {
                 regionCode = IntlUtility.GetRegionCodeFromTimeZone(defaultTimeZone);
             }
         }
         if (defaultLocale == null)
         {
             string systemLocale = CultureInfo.CurrentUICulture.Name;
             if (String.IsNullOrEmpty(systemLocale))
             {
                 defaultLocale = CldrUtility.GetDefaultLanguage(regionCode);
             }
             else
             {
                 defaultLocale = IntlUtility.CanonicalizeLanguageTag(systemLocale);
             }
         }
         if (isTimeZoneAutoDetected && IntlUtility.GetRegionCodeFromTimeZone(defaultTimeZone) == "001" && regionCode != "001")
         {
             string timeZone = IntlUtility.GetTimeZoneFromRegionCode(regionCode);
             if (timeZone != null && TZConvert.IanaToWindows(timeZone) == TZConvert.IanaToWindows(defaultTimeZone))
             {
                 defaultTimeZone = timeZone;
             }
         }
     }
 }