Пример #1
0
 private HDateTime(DateTimeOffset dto, HTimeZone htz)
 {
     m_dtoParsed = dto;
     TimeZone    = htz;
     date        = HDate.make(dto.Year, dto.Month, dto.Day);
     time        = HTime.make(dto.Hour, dto.Minute, dto.Second, dto.Millisecond);
 }
Пример #2
0
 // Constructor with basic fields
 public static HDateTime make(HDate date, HTime time, HTimeZone tz)
 {
     if (date == null || time == null || tz == null)
     {
         throw new ArgumentException("null args");
     }
     return(new HDateTime(date, time, tz));
 }
Пример #3
0
 // Private constructor
 private HDateTime(HDate date, HTime time, HTimeZone tz)
 {
     this.date   = date;
     this.time   = time;
     TimeZone    = tz;
     m_dtoParsed = new DateTimeOffset(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second, time.Millisecond, tz.dntz.BaseUtcOffset);
     // NOTE: Here offset is fixed - normal path is through other constructor for a parsed ISO string
 }
Пример #4
0
        // Equals is based on year, month, day
        public override bool hequals(object that)
        {
            if (!(that is HTime))
            {
                return(false);
            }
            HTime x = (HTime)that;

            return((Hour == x.Hour) && (Minute == x.Minute) && (Second == x.Second) && (Millisecond == x.Millisecond));
        }
Пример #5
0
        // Return sort order as negative, 0, or positive
        public override int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            HTime x = (HTime)obj;

            if (Hour < x.Hour)
            {
                return(-1);
            }
            else if (Hour > x.Hour)
            {
                return(1);
            }
            if (Minute < x.Minute)
            {
                return(-1);
            }
            else if (Minute > x.Minute)
            {
                return(1);
            }
            if (Second < x.Second)
            {
                return(-1);
            }
            else if (Second > x.Second)
            {
                return(1);
            }
            if (Millisecond < x.Millisecond)
            {
                return(-1);
            }
            else if (Millisecond > x.Millisecond)
            {
                return(1);
            }

            return(0);
        }
Пример #6
0
        // Parse from string fomat "hh:mm:ss.FF" or "hh:mm:ss" or raise FormatException (replaces ParseException)
        public static HTime make(string s)
        {
            string   strToConv = s;
            DateTime dtParsed  = DateTime.Now;
            string   strFormat = "";

            if (s.Contains("."))
            {
                strFormat = "HH:mm:ss.fff";
                // Unit tests show that the fff can't be more than 3 chars
                int iDotPos = strToConv.IndexOf(".");
                if ((strToConv.Length - iDotPos > 3) && (strToConv.Length > 12))
                {
                    strToConv = strToConv.Substring(0, 12);
                }
                else if ((strToConv.Length - iDotPos < 4) && (strToConv.Length < 12))
                {
                    // HH:mm:ss.ff
                    int iAddZeros = 3 - (strToConv.Length - iDotPos - 1);
                    for (int i = 0; i < iAddZeros; i++)
                    {
                        strToConv += '0';
                    }
                }
            }
            else
            {
                strFormat = "HH:mm:ss";
            }
            // Unit tests show that the fff can't be more than 3 chars

            if (!DateTime.TryParseExact(strToConv, strFormat,
                                        CultureInfo.InvariantCulture,
                                        DateTimeStyles.None,
                                        out dtParsed))
            {
                throw new FormatException("Invalid time string: " + s);
            }
            return(HTime.make(dtParsed.Hour, dtParsed.Minute, dtParsed.Second, dtParsed.Millisecond));
        }
Пример #7
0
 public static HaystackTime Map(HTime value)
 {
     return(value.Source);
 }
Пример #8
0
 // Constructor with date and time (to sec) fields
 public static HDateTime make(int year, int month, int day, int hour, int min, int sec, HTimeZone tz)
 {
     return(make(HDate.make(year, month, day), HTime.make(hour, min, sec), tz));
 }
 public static HDateTime make(HDate date, HTime time, HTimeZone tz) => M.Map(new HaystackDateTime(M.Map(date), M.Map(time), M.Map(tz)));