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); }
/** 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)); }
/** 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)); }
/** 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)); }
// 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)); }
// 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 }
/** 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)); }
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); }
/** 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)); }
/** * 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); }
// 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)); }
// 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))); }
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))));
// 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)));
// Make for single date within given timezone public static HDateTimeRange make(HDate date, HTimeZone tz) { return(make(date, date, tz)); }
public static HaystackDate Map(HDate value) { return(value.Source); }
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))));