Exemplo n.º 1
0
        internal ResultCode LoadTimeZoneRules(out TimeZoneRule outRules, string locationName)
        {
            outRules = new TimeZoneRule
            {
                Ats   = new long[TzMaxTimes],
                Types = new byte[TzMaxTimes],
                Ttis  = new TimeTypeInfo[TzMaxTypes],
                Chars = new char[TzCharsArraySize]
            };

            if (!IsLocationNameValid(locationName))
            {
                return(ResultCode.TimeZoneNotFound);
            }

            if (!HasTimeZoneBinaryTitle())
            {
                // If the user doesn't have the system archives, we generate a POSIX rule string and parse it to generate a incomplete TimeZoneRule
                // TODO: As for now not having system archives is fine, we should enforce the usage of system archives later.
                Logger.PrintWarning(LogClass.ServiceTime, "TimeZoneBinary system archive not found! Time conversions will not be accurate!");
                try
                {
                    TimeZoneInfo info      = TZConvert.GetTimeZoneInfo(locationName);
                    string       posixRule = PosixTimeZone.FromTimeZoneInfo(info);

                    if (!TimeZone.ParsePosixName(posixRule, out outRules))
                    {
                        return(ResultCode.TimeZoneConversionFailed);
                    }

                    return(0);
                }
                catch (TimeZoneNotFoundException)
                {
                    Logger.PrintWarning(LogClass.ServiceTime, $"Timezone not found for string: {locationName})");

                    return(ResultCode.TimeZoneNotFound);
                }
            }
            else
            {
                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      tzIfStream = romfs.OpenFile($"zoneinfo/{locationName}", OpenMode.Read).AsStream();

                    if (!TimeZone.LoadTimeZoneRules(out outRules, tzIfStream))
                    {
                        return(ResultCode.TimeZoneConversionFailed);
                    }
                }

                return(0);
            }
        }
Exemplo n.º 2
0
        public void Test_Posix_From_IANA_At_End_Of_Month(string input, int year, string expected)
        {
            string actual = PosixTimeZone.FromIanaTimeZoneName(input, year);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 3
0
        public void Test_Posix_From_IANA(string input, string expected)
        {
            string actual = PosixTimeZone.FromIanaTimeZoneName(input);

            Assert.Equal(expected, actual);
        }