/// <summary> /// زمان را به صورت رشته دریافت میکند و به صورت های مختلف تاریخ شمسی تبدیل میکند /// </summary> /// <param name="date_">زمان به صورت رشته</param> /// <param name="DateType"> /// Date : تاریخ به فارسی /// Time : زمان /// DateTime : تاریخ و زمان به طور کامل /// Ago : چند دقیقه ، ساعت یا روز پیش /// ShortDate :تاریخ /// </param> /// <returns>تاریخ تبدیل شده به صورت رشته</returns> public static string DateReturner(string date_, string DateType) { DateTime date = Convert.ToDateTime(date_); PersianDateTime persianDateTime = new PersianDateTime(date); if (DateType == "Date") { return(persianDateTime.ToLongDateString()); } else if (DateType == "Time") { return(persianDateTime.ToLongTimeString()); } else if (DateType == "DateTime") { return(persianDateTime.ToLongDateTimeString()); } else if (DateType == "Ago") { string LastSeen = ""; PersianDateTime PerNow = new PersianDateTime(DateTime.Now); var dateTest = PerNow.Subtract(persianDateTime); if (dateTest.Days < 1) { if (dateTest.Hours < 1) { LastSeen = dateTest.Minutes + " دقیقه ی پیش"; } else { LastSeen = dateTest.Hours + "ساعت پیش"; } } else { LastSeen = dateTest.Days + "روز پیش"; } return(LastSeen); } else if (DateType == "ShortDate") { return(persianDateTime.ToShortDateString()); } else { return(""); } }
public static ConcurrentDictionary <int, List <DayModel> > DeserializeJson(int persianYear, int persianMonth) { string json; try { var path = Path.Combine(Directory.GetCurrentDirectory(), JsonFilename); using var reader = new StreamReader(path); json = reader.ReadToEnd(); } catch (Exception ex) { Console.WriteLine(ex); json = ""; } if (string.IsNullOrEmpty(json)) { return(new ConcurrentDictionary <int, List <DayModel> >()); } var calendars = JToken.Parse(json); var monthResult = Init(); foreach (var calendar in calendars) { var calendarName = calendar["name"].ToString(); var calendarEvents = calendar["event"]; var date = (from month in calendarEvents select new MonthModel { MonthNo = Convert.ToInt32(((JProperty)month).Name), Days = (from day in month.First let @event = day.First.First["event"].Value <string>() let holiday = day.First.First["holiday"].Value <string>() let dayNo = Convert.ToInt32(((JProperty)day).Name) select new DayModel { DayOfMonth = dayNo, Events = @event.Split(new[] { "\r\n", "/", "؛" }, StringSplitOptions.None) .Select(x => x.Trim()).ToList(), IsHoliday = holiday == "1" }).ToList(), }).ToList(); if (date.Count <= 0) { continue; } DateTime rangeFrom; DateTime rangeTo; CalendarTypes calendarType; switch (calendarName) { case "jalali": rangeFrom = new PersianDateTime(persianYear, persianMonth, 1).ToDateTime(); rangeTo = new PersianDateTime(persianYear, persianMonth, GetMonthDays(persianMonth)).ToDateTime(); calendarType = CalendarTypes.Persian; break; case "miladi": rangeFrom = new PersianDateTime(persianYear, persianMonth, 1).ToDateTime(); rangeTo = new PersianDateTime(persianYear, persianMonth, GetMonthDays(persianMonth)).ToDateTime(); calendarType = CalendarTypes.Gregorian; break; case "hijri": default: rangeFrom = new PersianDateTime(persianYear, persianMonth, 1).ToDateTime(); rangeTo = new PersianDateTime(persianYear, persianMonth, GetMonthDays(persianMonth)).ToDateTime(); calendarType = CalendarTypes.Hijri; break; } var ranges = Enumerable.Range(0, rangeTo.Subtract(rangeFrom).Days + 1) .Select(d => rangeFrom.AddDays(d)).ToList(); monthResult.UpdateLibrary(date, ranges, calendarType); } return(monthResult); }