126 lines
3.6 KiB
C#
126 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace HSUCO_Cargo_Garage_Operation_Program
|
|
{
|
|
public static class Extends
|
|
{
|
|
/// <summary>
|
|
/// Database 저장용 Date와 Time 존재
|
|
/// </summary>
|
|
/// <param name="dateTime"></param>
|
|
/// <returns></returns>
|
|
public static string DateTimeDatabase(this DateTime dateTime)
|
|
{
|
|
return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
/// <summary>
|
|
/// 시간이 00:00:00 으로 된 버전
|
|
/// </summary>
|
|
/// <param name="date"></param>
|
|
/// <returns></returns>
|
|
public static string DateOnly(this DateTime date)
|
|
{
|
|
return date.ToString("yyyy-MM-dd 00:00:00");
|
|
}
|
|
/// <summary>
|
|
/// 시간이 00:00:00 으로 변경하여 출력
|
|
/// </summary>
|
|
/// <param name="date"></param>
|
|
/// <returns></returns>
|
|
public static string StartDateTime(this DateTime date)
|
|
{
|
|
return $"{date.Year:D4}-{date.Month:D2}-{date.Day:D2} 00:00:00";
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// 시간이 23:59:59 으로 변경하여 출력
|
|
/// </summary>
|
|
/// <param name="date"></param>
|
|
/// <returns></returns>
|
|
public static string EndDateTime(this DateTime date)
|
|
{
|
|
return $"{date.Year:D4}-{date.Month:D2}-{date.Day:D2} 23:59:59";
|
|
|
|
}
|
|
|
|
public static int BoolToInt(this bool value)
|
|
{
|
|
return value ? 1 : 0;
|
|
}
|
|
public static ProgressDays GetProgressDays(DateTime start, DateTime end)
|
|
{
|
|
ProgressDays progressDays = new ProgressDays();
|
|
DateTime midDay = new DateTime(start.Year, start.Month, 1);
|
|
if (start.Day != 1)
|
|
{
|
|
progressDays.StartDay = start.Day;
|
|
progressDays.StartTotalDay = DateTime.DaysInMonth(start.Year, start.Month);
|
|
midDay = midDay.AddMonths(1);
|
|
}
|
|
progressDays.Month = 0;
|
|
while (true)
|
|
{
|
|
DateTime get = new DateTime(midDay.Year, midDay.Month, DateTime.DaysInMonth(midDay.Year, midDay.Month));
|
|
if (get <= end.Date)
|
|
{
|
|
progressDays.Month++;
|
|
midDay = midDay.AddMonths(1);
|
|
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
return progressDays;
|
|
}
|
|
public static int GetProgressMonth(int startYear, int startMonth, int endYear, int endMonth)
|
|
{
|
|
DateTime progressDate = new DateTime(startYear, startMonth, 1);
|
|
DateTime endDate = new DateTime(endYear, endMonth, DateTime.DaysInMonth(endYear, endMonth));
|
|
int month = 0;
|
|
while (true)
|
|
{
|
|
|
|
if (progressDate <= endDate.Date)
|
|
{
|
|
month++;
|
|
progressDate = progressDate.AddMonths(1);
|
|
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
return month;
|
|
}
|
|
public static void Shuffle<T>(this IList<T> list)
|
|
{
|
|
Random random = new Random();
|
|
int n = list.Count;
|
|
while (n > 1)
|
|
{
|
|
n--;
|
|
int k = random.Next(n + 1);
|
|
T Value = list[k];
|
|
list[k] = list[n];
|
|
list[n] = Value;
|
|
}
|
|
}
|
|
}
|
|
public struct ProgressDays
|
|
{
|
|
public int StartDay;
|
|
public int StartTotalDay;
|
|
public int Month;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|