public HomeController(ILogger <HomeController> logger, DateContext d1)
        {
            d = d1;


            _logger = logger;
        }
Example #2
0
 //получение списка всех элементов в таблице
 public IEnumerable <Interval> GetAllIntervals()
 {
     using (DateContext db = new DateContext())
     {
         var intervalList = db.Intervals.ToList();
         return(intervalList);
     }
 }
Example #3
0
 public DateComparisonController(
     DateContext context,
     DateMapper dateMapper,
     FilterService filterService)
 {
     _context       = context;
     _dateMapper    = dateMapper;
     _filterService = filterService;
 }
        // parse a regex match which includes 'day', 'month' and 'year' (optional) group
        protected DateTimeResolutionResult Match2Date(Match match, DateObject referenceDate)
        {
            var ret = new DateTimeResolutionResult();

            var monthStr = match.Groups["month"].Value;
            var dayStr = match.Groups["day"].Value;
            var yearStr = match.Groups["year"].Value;
            var yearJapStr = match.Groups["yearJap"].Value;
            int month = 1, day = 1, year = 0;

            var tmp = ConvertJapaneseYearToInteger(yearJapStr);

            year = tmp == -1 ? 0 : tmp;

            if (this.config.MonthOfYear.ContainsKey(monthStr))
            {
                month = this.config.MonthOfYear[monthStr] > 12 ? this.config.MonthOfYear[monthStr] % 12 : this.config.MonthOfYear[monthStr];
                if (!string.IsNullOrEmpty(yearStr))
                {
                    year = int.Parse(yearStr, CultureInfo.InvariantCulture);
                    if (year < 100 && year >= Constants.MinTwoDigitYearPastNum)
                    {
                        year += 1900;
                    }
                    else if (year >= 0 && year < Constants.MaxTwoDigitYearFutureNum)
                    {
                        year += 2000;
                    }
                }

                if (this.config.DayOfMonth.ContainsKey(dayStr))
                {
                    day = this.config.DayOfMonth[dayStr] > 31 ? this.config.DayOfMonth[dayStr] % 31 : this.config.DayOfMonth[dayStr];
                }
            }

            var noYear = false;

            if (year == 0)
            {
                year      = referenceDate.Year;
                ret.Timex = DateTimeFormatUtil.LuisDate(-1, month, day);
                noYear    = true;
            }
            else
            {
                ret.Timex = DateTimeFormatUtil.LuisDate(year, month, day);
            }

            var futurePastDates = DateContext.GenerateDates(noYear, referenceDate, year, month, day);

            ret.FutureValue = futurePastDates.future;
            ret.PastValue   = futurePastDates.past;
            ret.Success     = true;

            return(ret);
        }
        private static void AddInitialData(DateContext context)
        {
            if (!context.DateComparisonObjects.Any())
            {
                context.DateComparisonObjects.AddRange(new List <DateComparisonObject> {
                    new DateComparisonObject(DateTime.UtcNow.EndOfDay().Ticks, DateTime.UtcNow.EndOfDay().AddDays(1).Ticks),
                    new DateComparisonObject(DateTime.UtcNow.EndOfDay().Ticks, DateTime.UtcNow.EndOfDay().AddDays(10).Ticks)
                });
            }

            context.SaveChanges();
        }
Example #6
0
 public IHttpActionResult PostInterval([FromBody] Interval interval)
 {
     if (ModelState.IsValid)
     {
         using (DateContext db = new DateContext())
         {
             db.Intervals.Add(interval);
             db.SaveChanges();
             return(CreatedAtRoute("DefaultApi", new { id = interval.Id }, interval));
         }
     }
     return(BadRequest(ModelState));
 }
        private void AddLoggableDate(object entity)
        {
            ILoggable loggable = entity as ILoggable;

            if (loggable != null && !loggable.IgnoreLoggableFieldsOnCommit)
            {
                DateTime now = DateContext.UTCNow();
                if (loggable.CreatedOn == default(DateTime))
                {
                    loggable.CreatedOn = now;
                }
                loggable.ModifiedOn = now;
            }
        }
Example #8
0
        //получение списка элементов, которые пересекаются с заданым интервалом
        public IHttpActionResult GetInterval(DateTime begin, DateTime due)
        {
            using (DateContext db = new DateContext())
            {
                var intervalList = db.Intervals.ToList();

                //проверка на пересечение
                var interval = intervalList.Where(u => begin <= u.DueDate && u.BeginDate <= due).ToList();
                if (interval == null)
                {
                    return(NotFound());
                }
                return(Ok(interval));
            }
        }
Example #9
0
        public void Correctly_determines_first_day_of_current_year()
        {
            MockRepository mocks = new MockRepository();
            ISystemClock   clock = mocks.CreateMock <ISystemClock>();

            using (mocks.Record())
            {
                Expect.Call(clock.GetCurrentDateTime()).Return(new DateTime(2007, 4, 15, 8, 15, 0));
            }

            using (mocks.Playback())
            {
                IDateContext context = new DateContext(clock);
                Assert.That(context.GetFirstDayOfCurrentYear(), Is.EqualTo(new DateTime(2007, 1, 1)));
            }

            mocks.VerifyAll();
        }
Example #10
0
        public void Correctly_gets_date_text_by_time_period()
        {
            MockRepository mocks = new MockRepository();
            ISystemClock   clock = mocks.CreateMock <ISystemClock>();

            using (mocks.Record())
            {
                Expect.Call(clock.GetCurrentDateTime()).Return(new DateTime(2007, 4, 15, 8, 15, 0)).Repeat.Times(3);
            }

            using (mocks.Playback())
            {
                IDateContext context = new DateContext(clock);
                Assert.That(context.GetTimePeriodName(TimePeriod.CurrentDay), Is.EqualTo("Today"));
                Assert.That(context.GetTimePeriodName(TimePeriod.CurrentMonth), Is.EqualTo("April, 2007"));
                Assert.That(context.GetTimePeriodName(TimePeriod.CurrentYear), Is.EqualTo("2007"));
                Assert.That(context.GetTimePeriodName(TimePeriod.AllTime), Is.EqualTo("All Time"));
            }

            mocks.VerifyAll();
        }
Example #11
0
        public void Correctly_gets_date_by_time_period()
        {
            MockRepository mocks = new MockRepository();
            ISystemClock   clock = mocks.CreateMock <ISystemClock>();

            using (mocks.Record())
            {
                Expect.Call(clock.GetCurrentDateTime()).Return(new DateTime(2007, 4, 15, 8, 15, 0)).Repeat.Times(3);
            }

            using (mocks.Playback())
            {
                IDateContext context = new DateContext(clock);
                Assert.That(context.GetFirstDayOfTimePeriod(TimePeriod.CurrentDay), Is.EqualTo(new DateTime(2007, 4, 15)));
                Assert.That(context.GetFirstDayOfTimePeriod(TimePeriod.CurrentMonth), Is.EqualTo(new DateTime(2007, 4, 1)));
                Assert.That(context.GetFirstDayOfTimePeriod(TimePeriod.CurrentYear), Is.EqualTo(new DateTime(2007, 1, 1)));
                Assert.That(context.GetFirstDayOfTimePeriod(TimePeriod.AllTime), Is.EqualTo(SqlDateTime.MinValue.Value));
            }

            mocks.VerifyAll();
        }
Example #12
0
 public StudentController(DateContext context)
 {
     _context = context;
 }
Example #13
0
 public DetailController(DateContext context)
 {
     _context = context;
 }
Example #14
0
        // match several other cases
        // including '今天', '后天', '十三日'
        protected DateTimeResolutionResult ParseImplicitDate(string text, DateObject referenceDate)
        {
            var ret = new DateTimeResolutionResult();

            // handle "十二日" "明年这个月三日" "本月十一日"
            var match = ChineseDateExtractorConfiguration.SpecialDate.MatchExact(text, trim: true);

            if (match.Success)
            {
                var yearStr  = match.Groups["thisyear"].Value;
                var monthStr = match.Groups["thismonth"].Value;
                var dayStr   = match.Groups["day"].Value;

                int month = referenceDate.Month, year = referenceDate.Year;
                var day = this.config.DayOfMonth[dayStr];

                bool hasYear = false, hasMonth = false;

                if (!string.IsNullOrEmpty(monthStr))
                {
                    hasMonth = true;
                    if (ChineseDateExtractorConfiguration.NextRe.Match(monthStr).Success)
                    {
                        month++;
                        if (month == Constants.MaxMonth + 1)
                        {
                            month = Constants.MinMonth;
                            year++;
                        }
                    }
                    else if (ChineseDateExtractorConfiguration.LastRe.Match(monthStr).Success)
                    {
                        month--;
                        if (month == Constants.MinMonth - 1)
                        {
                            month = Constants.MaxMonth;
                            year--;
                        }
                    }

                    if (!string.IsNullOrEmpty(yearStr))
                    {
                        hasYear = true;
                        if (ChineseDateExtractorConfiguration.NextRe.Match(yearStr).Success)
                        {
                            ++year;
                        }
                        else if (ChineseDateExtractorConfiguration.LastRe.Match(yearStr).Success)
                        {
                            --year;
                        }
                    }
                }

                ret.Timex = DateTimeFormatUtil.LuisDate(hasYear ? year : -1, hasMonth ? month : -1, day);

                DateObject futureDate, pastDate;

                if (day > GetMonthMaxDay(year, month))
                {
                    var futureMonth = month + 1;
                    var pastMonth   = month - 1;
                    var futureYear  = year;
                    var pastYear    = year;

                    if (futureMonth == Constants.MaxMonth + 1)
                    {
                        futureMonth = Constants.MinMonth;
                        futureYear  = year++;
                    }

                    if (pastMonth == Constants.MinMonth - 1)
                    {
                        pastMonth = Constants.MaxMonth;
                        pastYear  = year--;
                    }

                    var isFutureValid = DateObjectExtension.IsValidDate(futureYear, futureMonth, day);
                    var isPastValid   = DateObjectExtension.IsValidDate(pastYear, pastMonth, day);

                    if (isFutureValid && isPastValid)
                    {
                        futureDate = DateObject.MinValue.SafeCreateFromValue(futureYear, futureMonth, day);
                        pastDate   = DateObject.MinValue.SafeCreateFromValue(pastYear, pastMonth, day);
                    }
                    else if (isFutureValid && !isPastValid)
                    {
                        futureDate = pastDate = DateObject.MinValue.SafeCreateFromValue(futureYear, futureMonth, day);
                    }
                    else if (!isFutureValid && !isPastValid)
                    {
                        futureDate = pastDate = DateObject.MinValue.SafeCreateFromValue(pastYear, pastMonth, day);
                    }
                    else
                    {
                        // Fall back to normal cases, might lead to resolution failure
                        // TODO: Ideally, this failure should be filtered out in extract phase
                        futureDate = pastDate = DateObject.MinValue.SafeCreateFromValue(year, month, day);
                    }
                }
                else
                {
                    futureDate = DateObject.MinValue.SafeCreateFromValue(year, month, day);
                    pastDate   = DateObject.MinValue.SafeCreateFromValue(year, month, day);

                    if (!hasMonth)
                    {
                        if (futureDate < referenceDate)
                        {
                            if (IsValidDate(year, month + 1, day))
                            {
                                futureDate = futureDate.AddMonths(1);
                            }
                        }

                        if (pastDate >= referenceDate)
                        {
                            if (IsValidDate(year, month - 1, day))
                            {
                                pastDate = pastDate.AddMonths(-1);
                            }
                            else if (DateContext.IsFeb29th(year, month - 1, day))
                            {
                                pastDate = pastDate.AddMonths(-2);
                            }
                        }
                    }
                    else if (!hasYear)
                    {
                        if (futureDate < referenceDate)
                        {
                            if (IsValidDate(year + 1, month, day))
                            {
                                futureDate = futureDate.AddYears(1);
                            }
                        }

                        if (pastDate >= referenceDate)
                        {
                            if (IsValidDate(year - 1, month, day))
                            {
                                pastDate = pastDate.AddYears(-1);
                            }
                        }
                    }
                }

                ret.FutureValue = futureDate;
                ret.PastValue   = pastDate;
                ret.Success     = true;

                return(ret);
            }

            // handle cases like "昨日", "明日", "大后天"
            match = ChineseDateExtractorConfiguration.SpecialDayRegex.MatchExact(text, trim: true);

            if (match.Success)
            {
                var value = referenceDate.AddDays(ChineseDateTimeParserConfiguration.GetSwiftDay(match.Value));
                ret.Timex       = DateTimeFormatUtil.LuisDate(value);
                ret.FutureValue = ret.PastValue = DateObject.MinValue.SafeCreateFromValue(value.Year, value.Month, value.Day);
                ret.Success     = true;

                return(ret);
            }

            if (!ret.Success)
            {
                ret = MatchThisWeekday(text, referenceDate);
            }

            if (!ret.Success)
            {
                ret = MatchNextWeekday(text, referenceDate);
            }

            if (!ret.Success)
            {
                ret = MatchLastWeekday(text, referenceDate);
            }

            if (!ret.Success)
            {
                ret = MatchWeekdayAlone(text, referenceDate);
            }

            return(ret);
        }
Example #15
0
 public CategoryController(DateContext context)
 {
     _context = context;
 }
 public FilterService(DateContext context,
                      DateMapper dateMapper)
 {
     _context    = context;
     _dateMapper = dateMapper;
 }
Example #17
0
 public ValuesController(DateContext context)
 {
     _context = context;
 }
Example #18
0
 public ProductController(DateContext context)
 {
     _context = context;
 }
	public DateContext date() {
		DateContext _localctx = new DateContext(Context, State);
		EnterRule(_localctx, 282, RULE_date);
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 2339; date_value();
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}
 public override Expression VisitDate(DateContext context)
 {
     var value = context.GetText();
     var date = _dateParser.Parse(value);
     return Expression.Constant(date, typeof(DateTime));
 }
Example #21
0
 public MasterController(DateContext context)
 {
     _context = context;
 }