Пример #1
0
        private Microsoft.Office.Interop.Outlook.TimeZone WindowsTimeZone(string ianaZoneId)
        {
            Microsoft.Office.Interop.Outlook.TimeZones tzs = oApp.TimeZones;
            var utcZones = new[] { "Etc/UTC", "Etc/UCT", "UTC", "Etc/GMT" };

            if (utcZones.Contains(ianaZoneId, StringComparer.OrdinalIgnoreCase))
            {
                log.Fine("Timezone \"" + ianaZoneId + "\" mapped to \"UTC\"");
                return(tzs["UTC"]);
            }

            var tzdbSource = NodaTime.TimeZones.TzdbDateTimeZoneSource.Default;

            // resolve any link, since the CLDR doesn't necessarily use canonical IDs
            var links = tzdbSource.CanonicalIdMap
                        .Where(x => x.Value.Equals(ianaZoneId, StringComparison.OrdinalIgnoreCase))
                        .Select(x => x.Key);

            // resolve canonical zones, and include original zone as well
            var possibleZones = tzdbSource.CanonicalIdMap.ContainsKey(ianaZoneId)
                ? links.Concat(new[] { tzdbSource.CanonicalIdMap[ianaZoneId], ianaZoneId })
                : links;

            // map the windows zone
            var mappings = tzdbSource.WindowsMapping.MapZones;
            var item     = mappings.FirstOrDefault(x => x.TzdbIds.Any(possibleZones.Contains));

            if (item == null)
            {
                throw new System.ApplicationException("Timezone \"" + ianaZoneId + "\" has no mapping.");
            }
            log.Fine("Timezone \"" + ianaZoneId + "\" mapped to \"" + item.WindowsId + "\"");

            return(tzs[item.WindowsId]);
        }
Пример #2
0
        private Microsoft.Office.Interop.Outlook.TimeZone WindowsTimeZone(string ianaZoneId)
        {
            Microsoft.Office.Interop.Outlook.TimeZones tzs = oApp.TimeZones;
            var utcZones = new[] { "Etc/UTC", "Etc/UCT" };

            if (utcZones.Contains(ianaZoneId, StringComparer.OrdinalIgnoreCase))
            {
                log.Fine("Timezone \"" + ianaZoneId + "\" mapped to \"UTC\"");
                return(tzs["UTC"]);
            }

            var tzdbSource = NodaTime.TimeZones.TzdbDateTimeZoneSource.Default;
            // resolve any link, since the CLDR doesn't necessarily use canonical IDs
            var links = tzdbSource.CanonicalIdMap
                        .Where(x => x.Value.Equals(ianaZoneId, StringComparison.OrdinalIgnoreCase))
                        .Select(x => x.Key);
            var mappings = tzdbSource.WindowsMapping.MapZones;
            var item     = mappings.FirstOrDefault(x => x.TzdbIds.Any(links.Contains));

            if (item == null)
            {
                log.Warn("Timezone \"" + ianaZoneId + "\" could not find a mapping");
                return(null);
            }
            log.Fine("Timezone \"" + ianaZoneId + "\" mapped to \"" + item.WindowsId + "\"");

            return(tzs[item.WindowsId]);
        }