예제 #1
0
    protected virtual TimeInfo GetTimeInfo(string time, string offset, DateTime?minimumUtcStartDate = null)
    {
        string field = DefaultDateField;

        if (!String.IsNullOrEmpty(time) && time.Contains("|"))
        {
            string[] parts = time.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            field = parts.Length > 0 && AllowedDateFields.Contains(parts[0]) ? parts[0] : DefaultDateField;
            time  = parts.Length > 1 ? parts[1] : null;
        }

        var utcOffset = GetOffset(offset);

        // range parsing needs to be based on the user's local time.
        var range    = DateTimeRange.Parse(time, Foundatio.Utility.SystemClock.OffsetUtcNow.ToOffset(utcOffset));
        var timeInfo = new TimeInfo {
            Field = field, Offset = utcOffset, Range = range
        };

        if (minimumUtcStartDate.HasValue)
        {
            timeInfo.ApplyMinimumUtcStartDate(minimumUtcStartDate.Value);
        }

        timeInfo.AdjustEndTimeIfMaxValue();
        return(timeInfo);
    }