예제 #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
        /** Make a range which encompasses the previous year. */
        public static HDateTimeRange lastYear(HTimeZone tz)
        {
            HDate today = HDate.today();
            HDate first = HDate.make(today.Year - 1, 1, 1);
            HDate last  = HDate.make(today.Year - 1, 12, 31);

            return(make(first, last, tz));
        }
예제 #3
0
        /** Make a range which encompasses the current month. */
        public static HDateTimeRange thisMonth(HTimeZone tz)
        {
            HDate today = HDate.today();
            HDate first = HDate.make(today.Year, today.Month, 1);
            HDate last  = HDate.make(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month));

            return(make(first, last, tz));
        }
예제 #4
0
        /** Make a range which encompasses the current week.
         *  The week is defined as Sunday thru Saturday. */
        public static HDateTimeRange thisWeek(HTimeZone tz)
        {
            HDate today = HDate.today();
            HDate sun   = today.minusDays(today.weekday() - DayOfWeek.Sunday);
            HDate sat   = today.plusDays(DayOfWeek.Saturday - today.weekday());

            return(make(sun, sat, tz));
        }
예제 #5
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));
 }
예제 #6
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
 }
예제 #7
0
        /** Make a range which encompasses the previous week.
         *  The week is defined as Sunday thru Saturday. */
        public static HDateTimeRange lastWeek(HTimeZone tz)
        {
            HDate today = HDate.today();
            HDate prev  = today.minusDays(7);
            HDate sun   = prev.minusDays(prev.weekday() - DayOfWeek.Sunday);
            HDate sat   = prev.plusDays(DayOfWeek.Saturday - prev.weekday());

            return(make(sun, sat, tz));
        }
예제 #8
0
        public override bool hequals(object obj)
        {
            if (!(obj is HDate))
            {
                return(false);
            }
            HDate x = (HDate)obj;

            return(Year == x.Year && Month == x.Month && Day == x.Day);
        }
예제 #9
0
        /** Make a range which encompasses the previous month. */
        public static HDateTimeRange lastMonth(HTimeZone tz)
        {
            HDate    today       = HDate.today();
            DateTime dttoday     = new DateTime(today.Year, today.Month, today.Day);
            DateTime dtLastMonth = dttoday.AddMonths(-1);

            HDate lastMonth = HDate.make(dtLastMonth.Year, dtLastMonth.Month, dtLastMonth.Day);
            HDate first     = HDate.make(lastMonth.Year, lastMonth.Month, 1);
            HDate last      = HDate.make(lastMonth.Year, lastMonth.Month, DateTime.DaysInMonth(lastMonth.Year, lastMonth.Month));

            return(make(first, last, tz));
        }
예제 #10
0
        /**
         * Parse from string using the given timezone as context for
         * date based ranges.  The formats are:
         *  - "today"
         *  - "yesterday"
         *  - "{date}"
         *  - "{date},{date}"
         *  - "{dateTime},{dateTime}"
         *  - "{dateTime}"  // anything after given timestamp
         * Throw ParseException is invalid string format.
         */
        public static HDateTimeRange make(string str, HTimeZone tz)
        {
            // handle keywords
            str = str.Trim();
            if (str.CompareTo("today") == 0)
            {
                return(make(HDate.today(), tz));
            }
            if (str.CompareTo("yesterday") == 0)
            {
                return(make(HDate.today().minusDays(1), tz));
            }

            // parse scalars
            int  comma = str.IndexOf(',');
            HVal start = null, end = null;

            if (comma < 0)
            {
                start = new HZincReader(str).readVal();
            }
            else
            {
                start = new HZincReader(str.Substring(0, comma)).readVal();
                end   = new HZincReader(str.Substring(comma + 1)).readVal();
            }

            // figure out what we parsed for start,end
            if (start is HDate)
            {
                if (end == null)
                {
                    return(make((HDate)start, tz));
                }
                if (end is HDate)
                {
                    return(make((HDate)start, (HDate)end, tz));
                }
            }
            else if (start is HDateTime)
            {
                if (end == null)
                {
                    return(make((HDateTime)start, HDateTime.now(tz)));
                }
                if (end is HDateTime)
                {
                    return(make((HDateTime)start, (HDateTime)end));
                }
            }

            throw new FormatException("Invalid HDateTimeRange: " + str);
        }
예제 #11
0
        // Parse from string fomat "YYYY-MM-DD" or raise FormatException (ParseException)
        public static HDate make(string s)
        {
            DateTime dtParsed = DateTime.Now;

            if (!DateTime.TryParseExact(s, "yyyy'-'MM'-'dd",
                                        CultureInfo.InvariantCulture,
                                        DateTimeStyles.None,
                                        out dtParsed))
            {
                throw new FormatException("Invalid date string: " + s);
            }
            return(HDate.make(dtParsed.Year, dtParsed.Month, dtParsed.Day));
        }
예제 #12
0
 // Make for inclusive dates within given timezone
 public static HDateTimeRange make(HDate start, HDate end, HTimeZone tz)
 {
     return(make(start.midnight(tz), end.plusDays(1).midnight(tz)));
 }
예제 #13
0
 public static HDateTimeRange make(HDate start, HDate end, HTimeZone tz)
 => M.Map(new HaystackDateTimeRange(new HaystackDateTime(start.Source.Value, M.Map(tz)), new HaystackDateTime(end.Source.Value, M.Map(tz))));
예제 #14
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)));
예제 #16
0
 // Make for single date within given timezone
 public static HDateTimeRange make(HDate date, HTimeZone tz)
 {
     return(make(date, date, tz));
 }
예제 #17
0
 public static HaystackDate Map(HDate value)
 {
     return(value.Source);
 }
예제 #18
0
 public static HDateTimeRange make(HDate date, HTimeZone tz)
 => M.Map(new HaystackDateTimeRange(new HaystackDateTime(date.Source.Value, M.Map(tz)), new HaystackDateTime(date.Source.Value.AddDays(1), M.Map(tz))));