Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Anq Calc
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here bool hasDob2 = false; bool considerCurrentDate = true; Console.WriteLine("ANQ Calculator \n Consider Current Date For Calculation : {0} \n Has Dob2 : {1}",considerCurrentDate, hasDob2); var calOnDate = Convert.ToDateTime("2018/01/28"); var dob1 = Convert.ToDateTime("1952/08/30"); DateTime? dob2 = Convert.ToDateTime("1967/08/23"); if(!hasDob2) { dob2 = null; } if(considerCurrentDate){ calOnDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); } Console.WriteLine(calculateANQ(dob1,calOnDate).ToString("dd-MM-yyyy")); if(dob2.HasValue) Console.WriteLine(calculateANQ(dob1,dob2.Value,calOnDate).ToString("dd-MM-yyyy")); } public static int findMonthQuarter(DateTime date) { if (date.Month >= 1 && date.Month <= 3) return 1; else if (date.Month >= 4 && date.Month <= 6) return 2; else if (date.Month >= 7 && date.Month <= 9) return 3; else return 4; } public static DateTime calculateANQ(DateTime dob,DateTime calcOnDate) { var fromData = calcOnDate; var yearDiff = DateTime.UtcNow.Year - dob.Year; DateTime q1Ann = fromData, q2Ann = fromData, q3Ann = DateTime.UtcNow, q4Ann = fromData, nextyearAnn = fromData, ANQ = fromData, currentDate = fromData; var bday = dob.AddYears(yearDiff); var nextMonth = fromData.AddDays(30); switch (findMonthQuarter(dob)) { case 1: q1Ann = bday; q2Ann = q1Ann.AddMonths(3); q3Ann = q1Ann.AddMonths(6); q4Ann = q1Ann.AddMonths(9); nextyearAnn = q1Ann.AddMonths(12); break; case 2: q2Ann = bday; q1Ann = q2Ann.AddMonths(-3); q3Ann = q2Ann.AddMonths(3); q4Ann = q2Ann.AddMonths(6); nextyearAnn = q2Ann.AddMonths(9); break; case 3: q3Ann = bday; q2Ann = q3Ann.AddMonths(-3); q1Ann = q3Ann.AddMonths(-6); q4Ann = q3Ann.AddMonths(3); nextyearAnn = q3Ann.AddMonths(6); break; case 4: q4Ann = bday; q3Ann = q4Ann.AddMonths(-3); q2Ann = q4Ann.AddMonths(-6); q1Ann = q4Ann.AddMonths(-9); nextyearAnn = q4Ann.AddMonths(3); break; } switch (findMonthQuarter(currentDate)) { case 1: if (q1Ann.Date < nextMonth.Date && q1Ann.Date > currentDate.Date) ANQ = q1Ann; else if (q2Ann.Date < nextMonth.Date && q2Ann.Date > currentDate.Date) ANQ = q2Ann; else ANQ = nextMonth; break; case 2: if (q2Ann.Date < nextMonth.Date && q2Ann.Date > currentDate.Date) ANQ = q2Ann; else if (q3Ann.Date < nextMonth && q3Ann.Date > currentDate.Date) ANQ = q3Ann; else ANQ = nextMonth; break; case 3: if (q3Ann.Date < nextMonth.Date && q3Ann.Date > currentDate.Date) ANQ = q3Ann; else if (q4Ann.Date < nextMonth.Date && q4Ann.Date > currentDate.Date) ANQ = q4Ann; else ANQ = nextMonth; break; case 4: if (q4Ann.Date < nextMonth.Date && q4Ann.Date > currentDate.Date) ANQ = q4Ann; else if (nextyearAnn.Date < nextMonth.Date && nextyearAnn.Date > currentDate.Date) ANQ = nextyearAnn; else ANQ = nextMonth; break; } if (ANQ != nextMonth) ANQ = ANQ.AddDays(-1); return ANQ; } public static DateTime calculateANQ(DateTime dob1, DateTime dob2, DateTime calcOnDate) { var fromData = calcOnDate; var yearDiff1 = DateTime.UtcNow.Year - dob1.Year; var yearDiff2 = DateTime.UtcNow.Year - dob2.Year; DateTime q1Ann = fromData, q2Ann = fromData, q3Ann = fromData, q4Ann = fromData, nextyearAnn = fromData, ANQ = fromData, currentDate = fromData; DateTime q1Ann2 = fromData, q2Ann2 = fromData, q3Ann2 = fromData, q4Ann2 = fromData, nextyearAnn2 = fromData; var bday1 = dob1.AddYears(yearDiff1); var bday2 = dob2.AddYears(yearDiff2); var datelist = new List<DateTime>(); var nextMonth = DateTime.UtcNow.AddDays(30); switch (findMonthQuarter(dob1)) { case 1: q1Ann = bday1; q2Ann = q1Ann.AddMonths(3); q3Ann = q1Ann.AddMonths(6); q4Ann = q1Ann.AddMonths(9); nextyearAnn = q1Ann.AddMonths(12); break; case 2: q2Ann = bday1; q1Ann = q2Ann.AddMonths(-3); q3Ann = q2Ann.AddMonths(3); q4Ann = q2Ann.AddMonths(6); nextyearAnn = q2Ann.AddMonths(9); break; case 3: q3Ann = bday1; q2Ann = q3Ann.AddMonths(-3); q1Ann = q3Ann.AddMonths(-6); q4Ann = q3Ann.AddMonths(3); nextyearAnn = q3Ann.AddMonths(6); break; case 4: q4Ann = bday1; q3Ann = q4Ann.AddMonths(-3); q2Ann = q4Ann.AddMonths(-6); q1Ann = q4Ann.AddMonths(-9); nextyearAnn = q4Ann.AddMonths(3); break; } switch (findMonthQuarter(dob2)) { case 1: q1Ann2 = bday2; q2Ann2 = q1Ann2.AddMonths(3); q3Ann2 = q1Ann2.AddMonths(6); q4Ann2 = q1Ann2.AddMonths(9); nextyearAnn2 = q1Ann2.AddMonths(12); break; case 2: q2Ann2 = bday2; q1Ann2 = q2Ann2.AddMonths(-3); q3Ann2 = q2Ann2.AddMonths(3); q4Ann2 = q2Ann2.AddMonths(6); nextyearAnn2 = q2Ann2.AddMonths(9); break; case 3: q3Ann2 = bday2; q2Ann2 = q3Ann2.AddMonths(-3); q1Ann2 = q3Ann2.AddMonths(-6); q4Ann2 = q3Ann2.AddMonths(3); nextyearAnn2 = q3Ann2.AddMonths(6); break; case 4: q4Ann2 = bday2; q3Ann2 = q4Ann2.AddMonths(-3); q2Ann2 = q4Ann2.AddMonths(-6); q1Ann2 = q4Ann2.AddMonths(-9); nextyearAnn2 = q4Ann2.AddMonths(3); break; } switch (findMonthQuarter(currentDate)) { case 1: if (q1Ann.Date > currentDate.Date) datelist.Add(q1Ann); if (q2Ann.Date > currentDate.Date) datelist.Add(q2Ann); datelist.Add(nextMonth); if (q1Ann2.Date > currentDate.Date) datelist.Add(q1Ann2); if (q2Ann2.Date > currentDate.Date) datelist.Add(q2Ann2); break; case 2: if (q2Ann.Date > currentDate.Date) datelist.Add(q2Ann); if (q3Ann.Date > currentDate.Date) datelist.Add(q3Ann); datelist.Add(nextMonth); if (q2Ann2.Date > currentDate.Date) datelist.Add(q2Ann2); if (q3Ann2.Date > currentDate.Date) datelist.Add(q3Ann2); break; case 3: if (q3Ann.Date > currentDate.Date) datelist.Add(q3Ann); if (q4Ann.Date > currentDate.Date) datelist.Add(q4Ann); datelist.Add(nextMonth); if (q3Ann2.Date > currentDate.Date) datelist.Add(q3Ann2); if (q4Ann2.Date > currentDate.Date) datelist.Add(q4Ann2); break; case 4: if (q4Ann.Date > currentDate.Date) datelist.Add(q4Ann); if (nextyearAnn.Date > currentDate.Date) datelist.Add(nextyearAnn); datelist.Add(nextMonth); if (q4Ann2.Date > currentDate.Date) datelist.Add(q4Ann2); if (nextyearAnn2.Date > currentDate.Date) datelist.Add(nextyearAnn2); break; } var ANQ1 = datelist.OrderBy(x => x).FirstOrDefault(); if (ANQ1 != nextMonth) ANQ1 = ANQ1.AddDays(-1); return ANQ1; } } }
run
|
edit
|
history
|
help
0
Math
Recursion
IEqatable simple object compare
Get Distinct value using Group By , Having , Count in DataTable C#
Free cash app money
tamrin
Fibonachi
3
Fórum ➡ Border of a string S with at least 3 non-overlapping solutions ( yield version ) ♦
loop exmple