예제 #1
0
        private DateTime?GetUtcDate(CustomDateField dateField)
        {
            DateTime?result = null;

            TimeZoneItem tz        = EventTimezone.Item;
            DateTime     eventDate = dateField.DateTime;

            if (tz != null && eventDate != DateTime.MinValue)
            {
                // Ensure timezone is unspecified before converting to UTC
                eventDate = DateTime.SpecifyKind(eventDate, DateTimeKind.Unspecified);

                try
                {
                    TimeZoneInfo eventTimezone = TimeZoneInfo.FindSystemTimeZoneById(tz.Timezone.Raw);

                    DateTime eventUtcDate = TimeZoneInfo.ConvertTimeToUtc(eventDate, eventTimezone);

                    result = eventUtcDate;
                }
                catch { }
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Returns event start time in format 7:00pm EST
        /// </summary>
        /// <returns></returns>
        public string GetFormattedEventStartTime()
        {
            DateTime eventDate = EventStartDate.DateTime;

            if (eventDate != DateTime.MinValue)
            {
                TimeZoneItem timezone  = EventTimezone.Item;
                string       zoneLabel = (timezone != null) ? timezone.Abbreviation.Rendered : string.Empty;

                string meridian = eventDate.ToString("tt").ToLower();

                return(String.Format("{0:h:mm}{1} {2}", eventDate, meridian, zoneLabel));
            }

            return(String.Empty);
        }
예제 #3
0
        /// <summary>
        /// Loads cities from file
        /// </summary>
        private void LoadLocations()
        {
            lock (locker)
            {
                // Do not read cities again
                if (allLocations.Count > 0)
                {
                    return;
                }

                FileStream fileStream = null;
                try
                {
                    string stringPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Data", "Cities.dat");
                    fileStream = File.OpenRead(stringPath);

                    using (var fileReader = new StreamReader(fileStream, Encoding.UTF8))
                    {
                        string line = null;
                        while ((line = fileReader.ReadLine()) != null)
                        {
                            try
                            {
                                string[]     chunks    = line.Split('\t');
                                float        latitude  = float.Parse(chunks[4], CultureInfo.InvariantCulture);
                                float        longitude = float.Parse(chunks[5], CultureInfo.InvariantCulture);
                                float        elevation = float.Parse(string.IsNullOrWhiteSpace(chunks[15]) ? "0" : chunks[15], CultureInfo.InvariantCulture);
                                TimeZoneItem timeZone  = timeZones.FirstOrDefault(tz => tz.TimeZoneId.Equals(chunks[17], StringComparison.InvariantCultureIgnoreCase));

                                var names = new List <string>();
                                names.Add(chunks[1]);
                                names.AddRange(chunks[3].Split(','));

                                allLocations.Add(new GeoLocation()
                                {
                                    Names     = names.ToArray(),
                                    Country   = chunks[8],
                                    Elevation = elevation,
                                    Latitude  = latitude,
                                    Longitude = -longitude,
                                    TimeZone  = timeZone,
                                });
                            }
                            catch (Exception ex)
                            {
                                Log.Error($"Unable to parse geographical location, line = {line}, error: {ex}");
                            }
                        }
                    }
                    fileStream.Close();
                }
                catch (Exception ex)
                {
                    Log.Error($"Unable to load locations list, error: {ex}");
                }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                }
            }
            LocationsLoaded?.Invoke();
        }
 public TimeZoneEditViewModel()
 {
     TimeZone = new TimeZoneItem();
 }