Fix recupero dati

This commit is contained in:
Samuele Locatelli
2021-12-10 16:27:33 +01:00
parent d9004aa1ba
commit 15dbbcd486
2 changed files with 31 additions and 4 deletions
+3 -3
View File
@@ -47,17 +47,17 @@ namespace GPW.CORE.Data.Controllers
// recupero intero set dati timbrature e attività....
rawTimbExp = localDbCtx
.DbSetTimbratureExpl
.Where(x => x.IdxDipendente == idxDipendente && x.DataLav >= dtInizio && x.DataLav <= dtFine)
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.DataLav && x.DataLav <= dtFine)
.ToList();
rawTimbr = localDbCtx
.DbSetTimbrature
.Where(x => x.IdxDipendente == idxDipendente && x.DataOra >= dtInizio && x.DataOra <= dtFine)
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.DataOra && x.DataOra <= dtFine)
.ToList();
rawRegAtt = localDbCtx
.DbSetRegAttivita
.Where(x => x.IdxDipendente == idxDipendente && x.Inizio >= dtInizio && x.Inizio <= dtFine)
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.Inizio && x.Inizio <= dtFine)
.ToList();
// calcolo intervallo date...
+28 -1
View File
@@ -37,7 +37,7 @@ namespace GPW.CORE.Data
{
this.anno = year;
this.weekNumber = numWeek;
DateTime dtRif = new DateTime(year, 1, 4).AddDays(7 * numWeek);
DateTime dtRif = FirstDateOfWeekISO8601(year, numWeek);
DayOfWeek day = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(dtRif);
this.inizio = dtRif.Date.AddDays(1 - (int)day);
this.fine = dtRif.Date.AddDays(7 - (int)day);
@@ -67,5 +67,32 @@ namespace GPW.CORE.Data
// Return the week of our adjusted day
return CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(time, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
}
public static DateTime FirstDateOfWeekISO8601(int year, int weekOfYear)
{
DateTime jan1 = new DateTime(year, 1, 1);
int daysOffset = DayOfWeek.Thursday - jan1.DayOfWeek;
// Use first Thursday in January to get first week of the year as
// it will never be in Week 52/53
DateTime firstThursday = jan1.AddDays(daysOffset);
var cal = CultureInfo.CurrentCulture.Calendar;
int firstWeek = cal.GetWeekOfYear(firstThursday, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
var weekNum = weekOfYear;
// As we're adding days to a date in Week 1,
// we need to subtract 1 in order to get the right date for week #1
if (firstWeek == 1)
{
weekNum -= 1;
}
// Using the first Thursday as starting week ensures that we are starting in the right year
// then we add number of weeks multiplied with days
var result = firstThursday.AddDays(weekNum * 7);
// Subtract 3 days from Thursday to get Monday, which is the first weekday in ISO8601
return result.AddDays(-3);
}
}
}