コード例 #1
0
ファイル: HomeController.cs プロジェクト: orjan/time-tracker
        public ActionResult CloseTimeLog(CloseTimeLog closeTimeLog)
        {
            var timeLog = DocumentSession.Load<TimeLog>(closeTimeLog.TimeLogId);

            if (timeLog.UserId != Principal.Id)
            {
                throw new Exception("It's not possible to delete another users timelog...");
            }

            var duration = Duration(closeTimeLog, timeLog.StartTime);

            timeLog.Duration = duration;

            DocumentSession.Store(timeLog);

            return RedirectToAction("Index");
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: orjan/time-tracker
        private TimeSpan Duration(CloseTimeLog closeTimeLog, DateTimeOffset timeLog)
        {
            var fromDateTimeOffset = ZonedDateTime.FromDateTimeOffset(timeLog);
            var localTime = closeTimeLog.EndTime;

            if (localTime.Equals(LocalTime.Midnight))
            {
                var zonedDateTime = new ZonedDateTime(clock.Now, CurrentTimeZone);
                localTime = zonedDateTime.LocalDateTime.TimeOfDay;
            }

            var between = Period.Between(fromDateTimeOffset.LocalDateTime.TimeOfDay, localTime);
            var duration = between.ToDuration().ToTimeSpan();
            return duration;
        }