using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dates
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(DateTime.Today.ToLongDateString());
string[] date = { "", "" };
string input = "";
for (int j = 0; j > 3; j++)
{
Console.WriteLine("");
Console.WriteLine("Enter a date in YMD format:");
if (j == 0) input = "2015-07-01 2015-07-04";
else if (j == 1) input = "2015-12-01 2017-02-03";
else if (j == 2) input = "2022-09-05 2023-09-04";
try
{
date[0] = DateTime.Parse(input.Substring(0, 10)).ToLongDateString()
.Substring(DateTime.Parse(input.Substring(0, 10)).ToLongDateString().IndexOf(',') + 2);
Console.WriteLine(" " + date[0]);
date[1] = DateTime.Parse(input.Substring(11, 10)).ToLongDateString()
.Substring(DateTime.Parse(input.Substring(11, 10)).ToLongDateString().IndexOf(',') + 2);
Console.WriteLine(" " + date[1]);
// Remove equal stuffs
Console.WriteLine(" -" + date[0].Substring(date[0].Length - 5, 5));
Console.WriteLine(" -" + date[1].Substring(date[1].Length - 5, 5));
if (date[0].Substring(date[0].Length - 5, 5).Equals(date[1].Substring(date[1].Length - 5, 5)))
{
date[1] = date[1].Remove(date[1].Length - 5, 5); // Remove year from the second date
if (date[0].Substring(0, date[0].IndexOf(' ') - 1).Equals(date[1].Substring(0, date[1].IndexOf(' ') - 1)))
{
date[0] = date[0].Remove(date[0].Length - 5, 5); // Remove year from the first date
date[1] = date[1].Remove(0, date[1].IndexOf(' ') + 1); // Remove month from the second date
}
// If less than a year apart
else if ( (DateTime.Parse(date[1]).Subtract(DateTime.Parse(date[0])).TotalDays < 365 ) /*&& !(DateTime.Parse(date[0]).AddYears(1).Equals(DateTime.Parse(date[1])))*/ )
date[1] = date[1].Remove(date[1].Length - 5, 5); // Remove year from the first date
}
// Add suffixes to dates
for (int i = 0; i < 2; i++)
if (date[i].Substring(date[i].IndexOf(",") - 1, 1).Equals("1")) date[i] = date[i].Insert(date[i].IndexOf(","), "st");
else if (date[i].Substring(date[i].IndexOf(",") - 1, 1).Equals("2")) date[i] = date[i].Insert(date[i].IndexOf(","), "nd");
else if (date[i].Substring(date[i].IndexOf(",") - 1, 1).Equals("3")) date[i] = date[i].Insert(date[i].IndexOf(","), "rd");
else date[i] = date[i].Insert(date[i].IndexOf(","), "th");
for (int i = 0; i < 2; i++)
Console.WriteLine("date[{0}] = " + date[i], i);
Console.WriteLine(
((date[0].Substring(date[0].Length - 1).Equals(",")) ? (date[0].Remove(date[0].Length - 1)) : (date[0])) + " - " +
((date[1].Substring(date[1].Length - 1).Equals(",")) ? (date[1].Remove(date[1].Length - 1)) : (date[1])));
}
catch (FormatException) { Console.WriteLine("* Invalid date format: Most likely becuase that one of the dates doesn't exist"); }
catch (IndexOutOfRangeException) { Console.WriteLine("* Index ouf of range exexpetion"); }
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkxpbnE7CnVzaW5nIFN5c3RlbS5UZXh0Owp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nLlRhc2tzOwoKbmFtZXNwYWNlIERhdGVzCnsKICAgIGNsYXNzIFByb2dyYW0KICAgIHsKICAgICAgICBzdGF0aWMgdm9pZCBNYWluKHN0cmluZ1tdIGFyZ3MpCiAgICAgICAgewogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZShEYXRlVGltZS5Ub2RheS5Ub0xvbmdEYXRlU3RyaW5nKCkpOwogICAgICAgICAgICBzdHJpbmdbXSBkYXRlID0geyAiIiwgIiIgfTsKICAgICAgICAgICAgc3RyaW5nIGlucHV0ID0gIiI7CiAgICAgICAgCiAgICAgICAgICAgIGZvciAoaW50IGogPSAwOyBqID4gMzsgaisrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgiIik7CiAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgiRW50ZXIgYSBkYXRlIGluIFlNRCBmb3JtYXQ6Iik7CiAgICAgICAgICAgICAgICBpZiAoaiA9PSAwKSBpbnB1dCA9ICIyMDE1LTA3LTAxIDIwMTUtMDctMDQiOwogICAgICAgICAgICAgICAgZWxzZSBpZiAoaiA9PSAxKSBpbnB1dCA9ICIyMDE1LTEyLTAxIDIwMTctMDItMDMiOwogICAgICAgICAgICAgICAgZWxzZSBpZiAoaiA9PSAyKSBpbnB1dCA9ICIyMDIyLTA5LTA1IDIwMjMtMDktMDQiOwoKICAgICAgICAgICAgICAgIHRyeQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGRhdGVbMF0gPSBEYXRlVGltZS5QYXJzZShpbnB1dC5TdWJzdHJpbmcoMCwgMTApKS5Ub0xvbmdEYXRlU3RyaW5nKCkKICAgICAgICAgICAgICAgICAgICAgICAgLlN1YnN0cmluZyhEYXRlVGltZS5QYXJzZShpbnB1dC5TdWJzdHJpbmcoMCwgMTApKS5Ub0xvbmdEYXRlU3RyaW5nKCkuSW5kZXhPZignLCcpICsgMik7CiAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIiAiICsgZGF0ZVswXSk7CiAgICAgICAgICAgICAgICAgICAgZGF0ZVsxXSA9IERhdGVUaW1lLlBhcnNlKGlucHV0LlN1YnN0cmluZygxMSwgMTApKS5Ub0xvbmdEYXRlU3RyaW5nKCkKICAgICAgICAgICAgICAgICAgICAgICAgLlN1YnN0cmluZyhEYXRlVGltZS5QYXJzZShpbnB1dC5TdWJzdHJpbmcoMTEsIDEwKSkuVG9Mb25nRGF0ZVN0cmluZygpLkluZGV4T2YoJywnKSArIDIpOwogICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCIgIiArIGRhdGVbMV0pOwoKICAgICAgICAgICAgICAgICAgICAvLyBSZW1vdmUgZXF1YWwgc3R1ZmZzCiAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIiAgIC0iICsgZGF0ZVswXS5TdW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