diff --git a/DailyStatus.Common/BLL/WorkDaysCalculator.cs b/DailyStatus.Common/BLL/WorkDaysCalculator.cs index cc4a955..19bee49 100644 --- a/DailyStatus.Common/BLL/WorkDaysCalculator.cs +++ b/DailyStatus.Common/BLL/WorkDaysCalculator.cs @@ -8,9 +8,13 @@ namespace DailyStatus.Common.BLL public class WorkDaysCalculator { public TimeSpan MonthExpectedHours(DateTime todayWithHours, TimeSpan workDayStartHour, double numberOfWorkingHoursPerDay, params DateTime[] holidays) + { + return TimeExpectedHours(new DateTime(todayWithHours.Year, todayWithHours.Month, 1), todayWithHours, workDayStartHour, numberOfWorkingHoursPerDay, holidays); + } + public TimeSpan TimeExpectedHours(DateTime since, DateTime todayWithHours, TimeSpan workDayStartHour, double numberOfWorkingHoursPerDay, params DateTime[] holidays) { var today = todayWithHours.Date; - var first = new DateTime(today.Year, today.Month, 1); + var first = since; var workDayStart = today + workDayStartHour; var worktime = TimeSpan.FromHours(first.BusinessDaysUntil(today, holidays) * numberOfWorkingHoursPerDay); @@ -32,6 +36,11 @@ public TimeSpan ExpectedWorkedDays(TimeSpan workDayStartHour, double numberOfWor { return MonthExpectedHours(DateTime.Now, workDayStartHour, numberOfWorkingHoursPerDay, holidaysDuringWeek); } + + internal TimeSpan ExpectedWorkedDaysSince(DateTime since, TimeSpan workDayStartHour, double numberOfWorkingHoursPerDay, params DateTime[] holidaysDuringWeek) + { + return TimeExpectedHours(since, DateTime.Now, workDayStartHour, numberOfWorkingHoursPerDay, holidaysDuringWeek); + } } } diff --git a/DailyStatus.Common/Configuration/DailyStatusConfiguration.cs b/DailyStatus.Common/Configuration/DailyStatusConfiguration.cs index 236784f..0eaffa8 100644 --- a/DailyStatus.Common/Configuration/DailyStatusConfiguration.cs +++ b/DailyStatus.Common/Configuration/DailyStatusConfiguration.cs @@ -22,5 +22,6 @@ public class DailyStatusConfiguration public int HoursADay { get; set; } public long WorkspaceId { get; set; } public List Holidays { get; set; } + public DateTime SumSince { get; set; } } } diff --git a/DailyStatus.Common/TogglProxy.cs b/DailyStatus.Common/TogglProxy.cs index 9391672..fe3483c 100644 --- a/DailyStatus.Common/TogglProxy.cs +++ b/DailyStatus.Common/TogglProxy.cs @@ -40,6 +40,13 @@ public TimeSpan GetExpectedWorkingTime(WorkDay dayConfig) dayConfig.NumberOfWorkingHoursPerDay); } + public TimeSpan GetExpectedWorkingTime(WorkDay dayConfig, DateTime since) + { + return new WorkDaysCalculator() + .ExpectedWorkedDaysSince(since,TimeSpan.FromHours(dayConfig.WorkDayStartHour), + dayConfig.NumberOfWorkingHoursPerDay); + } + public TimeSpan GetDifference(TimeSpan expected, TimeSpan sum) { var diff = sum - expected; @@ -67,15 +74,18 @@ public class TogglStatus } public async Task GetStatus() + { + return await GetStatus(new DateTimeOffset(new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1))); + } + + public async Task GetStatus(DateTimeOffset since) { try { var workspace = await GetWorkspace(); - var today = DateTime.Today; - var offset = new DateTimeOffset(new DateTime(today.Year, today.Month, 1)); - var entries = await _togglApi.TimeEntries.GetAllSince(offset) + var entries = await _togglApi.TimeEntries.GetAllSince(since) .SelectMany(e => e) - .Where(e => !e.ServerDeletedAt.HasValue && e.Start > offset) + .Where(e => !e.ServerDeletedAt.HasValue && e.Start > since) .Where(e => e.WorkspaceId == workspace.Id) .ToList(); var sumSeconds = entries.Where(e => e.Duration.HasValue) diff --git a/DailyStatus.CommonTests/BLL/WorkDaysCalculatorTests.cs b/DailyStatus.CommonTests/BLL/WorkDaysCalculatorTests.cs index 48cefe4..5ebbf78 100644 --- a/DailyStatus.CommonTests/BLL/WorkDaysCalculatorTests.cs +++ b/DailyStatus.CommonTests/BLL/WorkDaysCalculatorTests.cs @@ -73,7 +73,7 @@ public void Given12_11_2019_ShouldReturn6Days_BecauseThereIsOneHolidayOn11_11() todayWithHours: new DateTime(2019, 11, 12), workDayStartHour: TimeSpan.FromHours(10), numberOfWorkingHoursPerDay: 8, - new DateTime(2019, 11, 11)); + new DateTime(2019, 11, 11)); var expected = TimeSpan.FromHours(6 * 8); Assert.AreEqual(expected, actual); } diff --git a/DailyStatus.UI/App.config b/DailyStatus.UI/App.config index 61841ef..0c9a66a 100644 --- a/DailyStatus.UI/App.config +++ b/DailyStatus.UI/App.config @@ -40,6 +40,9 @@ 1/01/2019,01/06/2019,04/21/2019,04/22/2019,05/01/2019,05/03/2019,06/09/2019,06/20/2019,08/15/2019,11/01/2019,11/11/2019,12/25/2019,12/26/2019 + + 2019-09-01 + diff --git a/DailyStatus.UI/DailyStatus.UI.csproj b/DailyStatus.UI/DailyStatus.UI.csproj index ef7e6d2..34d8741 100644 --- a/DailyStatus.UI/DailyStatus.UI.csproj +++ b/DailyStatus.UI/DailyStatus.UI.csproj @@ -117,6 +117,9 @@ App.xaml Code + + DateTimeSincePrompt.xaml + HourRatePrompt.xaml @@ -168,6 +171,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/DailyStatus.UI/Properties/Settings.Designer.cs b/DailyStatus.UI/Properties/Settings.Designer.cs index b5e2c05..0f92f08 100644 --- a/DailyStatus.UI/Properties/Settings.Designer.cs +++ b/DailyStatus.UI/Properties/Settings.Designer.cs @@ -95,5 +95,17 @@ public string holidays { this["holidays"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("2019-09-01")] + public global::System.DateTime sum_since { + get { + return ((global::System.DateTime)(this["sum_since"])); + } + set { + this["sum_since"] = value; + } + } } } diff --git a/DailyStatus.UI/Properties/Settings.settings b/DailyStatus.UI/Properties/Settings.settings index 3d5c20b..c33d0f5 100644 --- a/DailyStatus.UI/Properties/Settings.settings +++ b/DailyStatus.UI/Properties/Settings.settings @@ -20,5 +20,8 @@ 1/01/2019,01/06/2019,04/21/2019,04/22/2019,05/01/2019,05/03/2019,06/09/2019,06/20/2019,08/15/2019,11/01/2019,11/11/2019,12/25/2019,12/26/2019 + + 2019-09-01 + \ No newline at end of file diff --git a/DailyStatus.UI/SettingsManager.cs b/DailyStatus.UI/SettingsManager.cs index 9fff6d0..8783485 100644 --- a/DailyStatus.UI/SettingsManager.cs +++ b/DailyStatus.UI/SettingsManager.cs @@ -22,6 +22,7 @@ public static DailyStatusConfiguration LoadSettings() cfg.HoursADay = stg.hours_a_day; cfg.WorkspaceId = stg.api_workspaceid; cfg.Holidays = stg.holidays.Split(',').Select(str => DateTime.Parse(str, CultureInfo.InvariantCulture)).ToList(); + cfg.SumSince = stg.sum_since; return cfg; } @@ -34,6 +35,7 @@ public static void SaveSettings(DailyStatusConfiguration cfg) stg.start_hour = cfg.WorkDayStartHour; stg.hours_a_day = cfg.HoursADay; stg.holidays = string.Join(",", cfg.Holidays.Select(d => d.ToString(CultureInfo.InvariantCulture))); + stg.sum_since = cfg.SumSince; stg.Save(); } } diff --git a/DailyStatus.UI/View/DateTimeSincePrompt.xaml b/DailyStatus.UI/View/DateTimeSincePrompt.xaml new file mode 100644 index 0000000..09bcc6f --- /dev/null +++ b/DailyStatus.UI/View/DateTimeSincePrompt.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + +