|
@@ -0,0 +1,456 @@
|
|
|
+using DocumentFormat.OpenXml.Bibliography;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelBI.Models;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
|
+
|
|
|
+namespace TEAMModelBI.Tool
|
|
|
+{
|
|
|
+ public static class TimeHelper1
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 平年
|
|
|
+ /// </summary>
|
|
|
+ public static List<int> flatY = new() { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 闰年
|
|
|
+ /// </summary>
|
|
|
+ public static List<int> leapY = new() { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 通过时间戳转换为时间
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="timeStamp"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static DateTimeOffset GetDateTime(long timeStamp)
|
|
|
+ {
|
|
|
+ long begtime = timeStamp * 10000;
|
|
|
+ DateTimeOffset dt_1970 = new(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ long tricks_1970 = dt_1970.Ticks;//1970年1月1日刻度
|
|
|
+ long time_tricks = tricks_1970 + begtime;//日志日期刻度
|
|
|
+ DateTimeOffset dt = new DateTime(time_tricks);//转化为DateTime
|
|
|
+ return dt;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 通过string装换为时间并获取时间的年、月、日、一年第几天、小时
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="time">时间,例如:2022060706</param>
|
|
|
+ /// <param name="timeStrType">时间类型: 例如:yyyyMMddHH </param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static (int year,int month,int day, int days, int hour) GetDateTime(string time, string timeStrType = null)
|
|
|
+ {
|
|
|
+ string type = "yyyyMMddHH";
|
|
|
+ if (!string.IsNullOrEmpty(timeStrType))
|
|
|
+ {
|
|
|
+ type = timeStrType;
|
|
|
+ }
|
|
|
+
|
|
|
+ int year = 0, month = 0, day = 0, days = 0, hour = 0;
|
|
|
+ DateTimeOffset dateTime = new();
|
|
|
+ dateTime = DateTime.ParseExact(time, type, System.Globalization.CultureInfo.CurrentCulture);
|
|
|
+ year = dateTime.Year;
|
|
|
+ month = dateTime.Month;
|
|
|
+ day = dateTime.Day;
|
|
|
+ DateTimeOffset dt1 = new DateTime(year, 1, 1);
|
|
|
+
|
|
|
+ days = (dateTime.Date - dt1.Date).Days + 1;
|
|
|
+ hour = dateTime.Hour;
|
|
|
+
|
|
|
+ return (year, month, day, days, hour);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取月份的开始和结束时间戳 13位
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="year"></param>
|
|
|
+ /// <param name="month"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static (long start, long end) GetMonthStartEnd(int year, int month, bool dateLenth = true)
|
|
|
+ {
|
|
|
+ DateTimeOffset dtNew = new(year, month, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ long start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeMilliseconds();
|
|
|
+ if (dateLenth == false) start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
|
|
|
+ var ste = dtNew.AddMonths(1).AddDays(-1).Day;
|
|
|
+ long end = new DateTimeOffset(dtNew.Year, dtNew.Month, ste, 23, 59, 59,TimeSpan.Zero).ToUnixTimeMilliseconds();
|
|
|
+ // DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
|
|
|
+ if (dateLenth == false) end = new DateTimeOffset(dtNew.Year, dtNew.Month, dtNew.Day, 23, 59, 59, TimeSpan.Zero).ToUnixTimeSeconds();
|
|
|
+ //DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
|
|
|
+
|
|
|
+ return (start, end);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 通过时间获取当前年开始月份到现在月的开始时间到结束时间 现在月是当前天的结束时间
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="date"></param>
|
|
|
+ /// <param name="dateLenth"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static async Task<List<MonthStartEnd>> GetYearSataMthCtMth(DateTimeOffset date,bool dateLenth = true)
|
|
|
+ {
|
|
|
+ int year = date.Year;
|
|
|
+ int mth = date.Month;
|
|
|
+ int day = date.Day;
|
|
|
+
|
|
|
+ List<MonthStartEnd> monthStartEnds = new();
|
|
|
+ for (int i = 1; i <= mth; i++)
|
|
|
+ {
|
|
|
+ MonthStartEnd monthStartEnd = new() { yearMonth = $"{year}-{i}" };
|
|
|
+ //DateTime dt = DateTime.Parse($"{year}-{i}");
|
|
|
+ DateTimeOffset dtNew = new(year, i, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ long start = dtNew.ToUnixTimeMilliseconds();
|
|
|
+ if (dateLenth == false)
|
|
|
+ start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
|
|
|
+ monthStartEnd.start = start;
|
|
|
+ long end = 0;
|
|
|
+ if (i == mth)
|
|
|
+ {
|
|
|
+ end = DateTimeOffset.Parse($"{year}-{mth}-{day} 23:59:59").ToUnixTimeMilliseconds();
|
|
|
+ if (dateLenth == false)
|
|
|
+ end = DateTimeOffset.Parse($"{year}-{mth}-{day} 23:59:59").ToUnixTimeSeconds();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var ste = dtNew.AddMonths(1).AddDays(-1).Day;
|
|
|
+ end = DateTimeOffset.Parse($"{dtNew.Year}-{dtNew.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
|
|
|
+ if (dateLenth == false)
|
|
|
+ end = DateTimeOffset.Parse($"{dtNew.Year}-{dtNew.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
|
|
|
+ }
|
|
|
+ monthStartEnd.end = end;
|
|
|
+ monthStartEnds.Add(monthStartEnd);
|
|
|
+ }
|
|
|
+
|
|
|
+ return monthStartEnds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取今年12个月的月份开始和结束时间戳 13位 10位
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="year">年份</param>
|
|
|
+ /// <param name="dateLenth">true :13位时间戳 false:10位时间戳</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static List<MonthStartEnd> GetYearMonthlyStartEnd(int year, bool dateLenth = true)
|
|
|
+ {
|
|
|
+ List<MonthStartEnd> monthStartEnds = new();
|
|
|
+ for (int i = 1; i <= 12; i++)
|
|
|
+ {
|
|
|
+ MonthStartEnd monthStartEnd = new MonthStartEnd() { yearMonth = $"{year}-{i}" };
|
|
|
+ //DateTime dt = DateTime.Parse($"{year}-{i}");
|
|
|
+ DateTimeOffset dtNew = new(year, i, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ long start = dtNew.ToUnixTimeMilliseconds();
|
|
|
+ if (dateLenth == false)
|
|
|
+ start = dtNew.ToUnixTimeSeconds();
|
|
|
+ monthStartEnd.start = start;
|
|
|
+ var ste = dtNew.AddMonths(1).AddDays(-1).Day;
|
|
|
+ long end = DateTimeOffset.Parse($"{dtNew.Year}-{dtNew.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
|
|
|
+ if (dateLenth == false)
|
|
|
+ end = DateTimeOffset.Parse($"{dtNew.Year}-{dtNew.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
|
|
|
+ monthStartEnd.end = end;
|
|
|
+ monthStartEnds.Add(monthStartEnd);
|
|
|
+ }
|
|
|
+
|
|
|
+ return monthStartEnds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取过去12个月的每月开始和结束的时间戳
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="yearMonth">日期</param>
|
|
|
+ /// <param name="dateLenth">true :13位时间戳 false:10位时间戳</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static List<MonthStartEnd> monthsOfYear(string yearMonth, bool dateLenth = true)
|
|
|
+ {
|
|
|
+ List<MonthStartEnd> monthStartEnds = new();
|
|
|
+ DateTime dateTime = DateTime.Parse(yearMonth);
|
|
|
+
|
|
|
+ int year = dateTime.Year;
|
|
|
+ int month = dateTime.Month;
|
|
|
+ List<string> months = new List<string>();
|
|
|
+ while (year > dateTime.Year - 1 || month > dateTime.Month)
|
|
|
+ {
|
|
|
+ MonthStartEnd monthStartEnd = new MonthStartEnd() { yearMonth = $"{year}-{month}" };
|
|
|
+
|
|
|
+ DateTimeOffset dtNew = new(year, month, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ long start = dateLenth ? dtNew.ToUnixTimeMilliseconds() : dtNew.ToUnixTimeSeconds();
|
|
|
+ monthStartEnd.start = start;
|
|
|
+ var ste = dtNew.AddMonths(1).AddDays(-1).Day;
|
|
|
+ long end = dateLenth ? DateTimeOffset.Parse($"{dateTime.Year}-{dateTime.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{dateTime.Year}-{dateTime.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
|
|
|
+ monthStartEnd.end = end;
|
|
|
+
|
|
|
+ monthStartEnds.Add(monthStartEnd);
|
|
|
+
|
|
|
+ months.Add($"{year}-{(month < 10 ? "0" : "") + month}");
|
|
|
+ month -= 1;
|
|
|
+ if (month <= 0)
|
|
|
+ {
|
|
|
+ year -= 1;
|
|
|
+ month = 12;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return monthStartEnds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取传过来的时间学期的开始时间戳和结束时间
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dateTime">日期</param>
|
|
|
+ /// <param name="dateLenth">true :13位时间戳 false:10位时间戳 </param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static (long start, long end) GetTermStartOrEnd(DateTimeOffset dateTime, bool dateLenth = true)
|
|
|
+ {
|
|
|
+ long start = 0;
|
|
|
+ long end = 0;
|
|
|
+ //DateTime dateTime = tempDateTime;
|
|
|
+ int year = dateTime.Year;
|
|
|
+ int month = dateTime.Month;
|
|
|
+ if (month <= 8 && month >= 3)
|
|
|
+ {
|
|
|
+ DateTimeOffset newStart = new(year, 3, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ start = dateLenth ? DateTimeOffset.Parse($"{newStart}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{newStart}").ToUnixTimeSeconds();
|
|
|
+
|
|
|
+ DateTimeOffset newEnd = new(year, 8, 31, 23, 59, 59, TimeSpan.Zero);
|
|
|
+ end = dateLenth ? DateTimeOffset.Parse($"{newEnd}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{newEnd}").ToUnixTimeSeconds();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //计算当前月份
|
|
|
+ int days = 0;
|
|
|
+ if (month >= 9)
|
|
|
+ {
|
|
|
+ DateTimeOffset newStart = new(dateTime.Year, 9, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ start = dateLenth ? newStart.ToUnixTimeMilliseconds() : newStart.ToUnixTimeSeconds();
|
|
|
+
|
|
|
+ DateTimeOffset newEnd = new(dateTime.Year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59, TimeSpan.Zero);
|
|
|
+ end = dateLenth ? newEnd.ToUnixTimeMilliseconds() : newEnd.ToUnixTimeSeconds();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DateTimeOffset newStart = new(dateTime.Year - 1, 9, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ start = dateLenth ? newStart.ToUnixTimeMilliseconds() : newStart.ToUnixTimeSeconds();
|
|
|
+
|
|
|
+ DateTimeOffset newEnd = new(dateTime.Year, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59, TimeSpan.Zero);
|
|
|
+ end = dateLenth ? newEnd.ToUnixTimeMilliseconds() : newEnd.ToUnixTimeSeconds();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return (start, end);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 开始时间和结束时间戳
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dateTime"></param>
|
|
|
+ /// <param name="type"></param>
|
|
|
+ /// <param name="dateLenth"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static (long start, long end) GetStartOrEnd(DateTimeOffset dateTime, string type = "", bool dateLenth = true)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ long start = 0;
|
|
|
+ long end = 0;
|
|
|
+ int year = dateTime.Year;
|
|
|
+ int month = dateTime.Month;
|
|
|
+ int day = dateTime.Day;
|
|
|
+ int hour = dateTime.Hour;
|
|
|
+ DateTimeOffset tempStrart = new();
|
|
|
+ DateTimeOffset tempEnd = new();
|
|
|
+ switch (type)
|
|
|
+ {
|
|
|
+ //今年开始、结束
|
|
|
+ case "yearMonth":
|
|
|
+ tempStrart = new DateTimeOffset(year, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59, TimeSpan.Zero);
|
|
|
+ break;
|
|
|
+ //今年开始、结束
|
|
|
+ case "year":
|
|
|
+ tempStrart = new DateTimeOffset(year, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year, 12, DateTime.DaysInMonth(year, 12), 23, 59, 59, TimeSpan.Zero);
|
|
|
+ break;
|
|
|
+ //去年开始、结束
|
|
|
+ case "lastYear":
|
|
|
+ tempStrart = new DateTimeOffset(year - 1, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year - 1, 12, DateTime.DaysInMonth(year, 12), 23, 59, 59, TimeSpan.Zero);
|
|
|
+ break;
|
|
|
+ //本学期
|
|
|
+ case "term":
|
|
|
+ if (month <= 8 && month >= 3)
|
|
|
+ {
|
|
|
+ tempStrart = new DateTimeOffset(year, 3, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year, 8, 31, 23, 59, 59, TimeSpan.Zero);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //计算当前月份
|
|
|
+ int days = 0;
|
|
|
+ if (month >= 9)
|
|
|
+ {
|
|
|
+ tempStrart = new DateTimeOffset(year, 9, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59, TimeSpan.Zero);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tempStrart = new DateTimeOffset(year - 1, 9, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59, TimeSpan.Zero);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ //上学期
|
|
|
+ case "lastterm":
|
|
|
+ DateTimeOffset tempDate = new();
|
|
|
+ if (dateTime.Month > 9)
|
|
|
+ tempDate = new DateTimeOffset(year, dateTime.Month - 4, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ else tempDate = new DateTimeOffset(year - 1, 9, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ if (!string.IsNullOrEmpty($"{tempDate}"))
|
|
|
+ {
|
|
|
+ year = tempDate.Year;
|
|
|
+ month = tempDate.Month;
|
|
|
+ if (month <= 8 && month >= 3)
|
|
|
+ {
|
|
|
+ tempStrart = new DateTimeOffset(year, 3, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year, 8, 31, 23, 59, 59,TimeSpan.Zero);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //计算当前月份
|
|
|
+ int days = 0;
|
|
|
+ if (month >= 9)
|
|
|
+ {
|
|
|
+ tempStrart = new DateTimeOffset(year, 9, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59,TimeSpan.Zero);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tempStrart = new DateTimeOffset(year - 1, 9, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59, TimeSpan.Zero);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ //上个月
|
|
|
+ case "lastMonth":
|
|
|
+ tempStrart = new DateTimeOffset(year, month - 1, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year, month - 1, DateTime.DaysInMonth(year, month - 1), 23, 59, 59, TimeSpan.Zero);
|
|
|
+ break;
|
|
|
+ //本月1号至当天
|
|
|
+ case "monthDay":
|
|
|
+ tempStrart = new DateTimeOffset(year, month, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year, month, day, 23, 59, 59, TimeSpan.Zero);
|
|
|
+ break;
|
|
|
+ //本月
|
|
|
+ case "month":
|
|
|
+ tempStrart = new DateTimeOffset(year, month, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59, TimeSpan.Zero);
|
|
|
+ break;
|
|
|
+ //上周
|
|
|
+ case "week":
|
|
|
+ DateTimeOffset weekStrart = dateTime.AddDays(-(int)(dateTime.DayOfWeek) + 1);
|
|
|
+ DateTimeOffset weekEnd = dateTime.AddDays(7 - (int)(dateTime.DayOfWeek));
|
|
|
+ tempStrart = new DateTimeOffset(weekStrart.Year, weekStrart.Month, weekStrart.Day, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(weekEnd.Year, weekEnd.Month, weekEnd.Day, 23, 59, 59, TimeSpan.Zero);
|
|
|
+ break;
|
|
|
+ //上周
|
|
|
+ case "lastweek":
|
|
|
+ var m = (dateTime.DayOfWeek == DayOfWeek.Sunday ? (DayOfWeek)7 : dateTime.DayOfWeek) - DayOfWeek.Monday;
|
|
|
+ var s = (dateTime.DayOfWeek == DayOfWeek.Sunday ? (DayOfWeek)7 : dateTime.DayOfWeek) - (DayOfWeek)7;
|
|
|
+ var Mon = dateTime.AddDays((-7 - m));//星期一
|
|
|
+ var Sun = dateTime.AddDays((-7 - s)); //星期日
|
|
|
+ tempStrart = new DateTimeOffset(Mon.Year, Mon.Month, Mon.Day, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(Sun.Year, Sun.Month, Sun.Day, 23, 59, 59, TimeSpan.Zero);
|
|
|
+ break;
|
|
|
+ //当前小时
|
|
|
+ case "hour":
|
|
|
+ tempStrart = new DateTimeOffset(year, month, day, hour, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year, month, day, hour, 59, 59, TimeSpan.Zero);
|
|
|
+
|
|
|
+ break;
|
|
|
+ //当天
|
|
|
+ default:
|
|
|
+ tempStrart = new DateTimeOffset(year, month, day, 0, 0, 0, TimeSpan.Zero);
|
|
|
+ tempEnd = new DateTimeOffset(year, month, day, 23, 59, 59, TimeSpan.Zero);
|
|
|
+ //start = dateLenth ? DateTimeOffset.Parse($"{dayStart}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{dayStart}").ToUnixTimeSeconds();
|
|
|
+ //end = dateLenth ? DateTimeOffset.Parse($"{dayEnd}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{dayEnd}").ToUnixTimeSeconds();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ start = dateLenth ? tempStrart.ToUnixTimeMilliseconds() : tempStrart.ToUnixTimeSeconds();
|
|
|
+ end = dateLenth ? tempEnd.ToUnixTimeMilliseconds() : tempEnd.ToUnixTimeSeconds();
|
|
|
+
|
|
|
+ return (start, end);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 将时间戳格式 转换成string类型
|
|
|
+ /// 例:yyyyMMdd,等string类型
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="unixTime"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static (string timeStart,string timeEnd) GetUnixToDate(long start,long end = 0,string types="yyyyMMdd")
|
|
|
+ {
|
|
|
+ string tStart = "";
|
|
|
+ string tEnd = "";
|
|
|
+ DateTimeOffset time = System.TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0));
|
|
|
+ tStart = time.AddMilliseconds(start).ToString($"{types}");
|
|
|
+ if (end > 0)
|
|
|
+ {
|
|
|
+ tEnd = time.AddMilliseconds(end).ToString($"{types}");
|
|
|
+ }
|
|
|
+
|
|
|
+ return (tStart, tEnd);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取每天的时间
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dateTime">时间</param>
|
|
|
+ /// <param name="dayNumber">最近几天</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static List<string> GetNearDay(DateTimeOffset dateTime,int dayNumber)
|
|
|
+ {
|
|
|
+ List<string> days = new();
|
|
|
+
|
|
|
+ days = Enumerable.Range(1, dayNumber).Select(i => dateTime.Date.AddDays(-i).ToString("yyyyMMdd")).ToList();
|
|
|
+
|
|
|
+ return days;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static List<YearMonth> GetYearMonth(List<double> doubles, int year = 0,int month = 0)
|
|
|
+ {
|
|
|
+ List<YearMonth> months = new();
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.Now;
|
|
|
+ if (year == 0)
|
|
|
+ year = dateTime.Year;
|
|
|
+ if(month == 0)
|
|
|
+ month = dateTime.Month;
|
|
|
+
|
|
|
+ List<int> isLeapYear = (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? isLeapYear = leapY : isLeapYear = flatY;
|
|
|
+ double[] array = doubles.ToArray();
|
|
|
+ double ser = doubles.Sum();
|
|
|
+ int moth = 1;
|
|
|
+ int primaryD = 0;
|
|
|
+ for (int i = 0; i < isLeapYear.Count; i++)
|
|
|
+ {
|
|
|
+ if (month < moth)
|
|
|
+ break;
|
|
|
+ double[] temp = new double[isLeapYear[i]];
|
|
|
+ Array.ConstrainedCopy(array, primaryD, temp, 0, isLeapYear[i]);
|
|
|
+ months.Add(new YearMonth() { id = $"{year}-{moth}", cnt = temp.Sum() });
|
|
|
+ moth += 1;
|
|
|
+ primaryD += isLeapYear[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ return months;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|