コード例 #1
0
 //ctor
 public AprsPacket()
 {
     Position  = new Position();
     TimeStamp = new TimeInfo();
     Comment   = string.Empty;
 }
コード例 #2
0
        private void ParseDateTime(string str)
        {
            try
            {
                if (string.IsNullOrEmpty(str))
                {
                    return;
                }

                //assume current date/time
                TimeStamp.TimeStamp = DateTime.UtcNow;

                //we should see one of the following strings
                //  DDHHMM[z|/]                      (time is z=UTC /=local)
                //  HHMMSSh                          (time is UTC)
                //  NNDDHHMM      NN is month number (time is UTC)

                int day, hour, minute;

                int l = str.Length;
                if (str[l - 1] == 'z' || str[l - 1] == '/') //If this is UTC or local time
                {
                    try
                    {
                        day    = int.Parse(str.Substring(0, 2));
                        hour   = int.Parse(str.Substring(2, 2));
                        minute = int.Parse(str.Substring(4, 2));
                        TimeStamp.TimeStamp = new DateTime(TimeStamp.TimeStamp.GetValueOrDefault().Year,
                                                           TimeStamp.TimeStamp.GetValueOrDefault().Month,
                                                           day, hour, minute, 0);

                        if (str[l - 1] == '/')
                        {
                            TimeStamp.IsLocalTime = true;
                        }
                    }
                    catch (Exception)
                    {
                        TimeStamp.TimeStamp = DateTime.UtcNow;
                    }
                }
                else if (str[l - 1] == 'h')
                {
                    hour   = int.Parse(str.Substring(0, 2));
                    minute = int.Parse(str.Substring(2, 2));
                    int second = int.Parse(str.Substring(4, 2));
                    TimeStamp.TimeStamp = new DateTime(TimeStamp.TimeStamp.GetValueOrDefault().Year,
                                                       TimeStamp.TimeStamp.GetValueOrDefault().Month,
                                                       TimeStamp.TimeStamp.GetValueOrDefault().Day, hour, minute, second);
                }
                else if (l == 8)
                {
                    int month = int.Parse(str.Substring(0, 2));
                    day    = int.Parse(str.Substring(2, 2));
                    hour   = int.Parse(str.Substring(4, 2));
                    minute = int.Parse(str.Substring(6, 2));
                    TimeStamp.TimeStamp = new DateTime(TimeStamp.TimeStamp.GetValueOrDefault().Year,
                                                       month, day, hour, minute, 0);
                }
                else
                {
                    TimeStamp.TimeStamp = null;
                }
            }
            catch (Exception)
            {
                TimeStamp = null;
            }
        }