using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; using System.Text; namespace ProductionLineMonitor.Core.Utils { public class DateTimeHelper { public static void GetStartEndTime(DateTime date, out DateTime startTime, out DateTime endTime) { int year, month, day; year = date.Year; month = date.Month; day = date.Day; if (day < 21) { month -= 1; if (month == 0) { year -= 1; month = 12; } } startTime = Convert.ToDateTime($"{year}-{month}-21 08:00:00"); endTime = startTime.AddMonths(1).AddDays(-1); } public static List GetDate(DateTime startTime, DateTime endTime) { List rev = new List(); for (DateTime dt = startTime; dt <= endTime; dt = dt.AddDays(+1)) { rev.Add(dt.ToString("yyyy-MM-dd")); } return rev; } public static List GetDateTime(DateTime startTime, DateTime endTime) { List rev = new List(); for (DateTime dt = startTime; dt < endTime; dt = dt.AddDays(+1)) { rev.Add(dt); } return rev; } public static List GetDateString(DateTime startTime, DateTime endTime) { List rev = new List(); for (DateTime dt = startTime; dt <= endTime; dt = dt.AddDays(+1)) { rev.Add(dt.ToString("yyyy-MM-dd")); } return rev; } public static List GetDateShift(DateTime startTime, DateTime endTime) { List rev = new List(); for (DateTime dt = startTime; dt <= endTime; dt = dt.AddDays(+1)) { rev.Add(dt.ToString("yyyy-MM-dd 08:00:00")); rev.Add(dt.ToString("yyyy-MM-dd 20:00:00")); } return rev; } public static List GetDateShiftV1(DateTime startTime, DateTime endTime) { List rev = new List(); for (DateTime dt = startTime; dt <= endTime; dt = dt.AddDays(+1)) { rev.Add(dt.ToString("yyyy-MM-dd 白班")); rev.Add(dt.ToString("yyyy-MM-dd 夜班")); } return rev; } } }