Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication25
- {
- public delegate void isDateValid(int falseInfo, string falseType);
- enum Months : byte { January, February, March, April, May, June, July, August, September, October, November, December, False };
- public class Date
- {
- private int year;
- private Months month;
- private int day;
- private bool isFalse = false;
- public isDateValid dateCheck;
- public Date(int year, int month, int day)
- {
- this.year = year;
- if (month > 0 && month < 13)
- {
- this.month = (Months)month-1;
- }
- else
- {
- this.month = (Months)13;
- isFalse = true;
- }
- this.day = day;
- }
- public void DayMonthCheck()
- {
- if (month != (Months) 13)
- {
- if ((int)month > 2 && (int)month < 8)
- {
- if ((int)month % 2 == 0)
- {
- if (day > 30)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- else
- {
- if (day > 31)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- }
- else if ((int)month >= 8)
- {
- if( (int) month % 2 == 0)
- {
- if (day > 31)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- else
- {
- if (day > 30)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- }
- else if ((int)month == 1)
- {
- if (day > 31)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- else if ((int)month == 2)
- {
- if (day > 28)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- }
- else
- dateCheck((int)month, "month");
- if (day < 1)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- public static void Sub()
- {
- }
- public void Print(int selectedOutput)
- {
- if (!isFalse)
- {
- if (selectedOutput == 1)
- Console.WriteLine("{0}/{1}/{2}", day, (int)month+1, year);
- else if (selectedOutput == 2)
- Console.WriteLine("{0} {1}, {2}", day, month, year);
- else if (selectedOutput == 3)
- Console.WriteLine("{0} - {1} - {2}", day, (int)month+1, year);
- else
- Console.WriteLine("{0}/{1}/{2}", (int)month+1, day, year);
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Year: ");
- int year = int.Parse(Console.ReadLine());
- Console.Write("Month: ");
- int month = int.Parse(Console.ReadLine());
- Console.Write("Day: ");
- int day = int.Parse(Console.ReadLine());
- Date today = new Date(year, month, day);
- today.dateCheck = new isDateValid(DateValidation);
- today.DayMonthCheck();
- Console.WriteLine("Choose printing method:");
- Console.WriteLine("1. dd/mm/yy\n2. dd Month, yy\n3. dd-mm-yy\n4. mm/dd/yy");
- int selectedOutput = int.Parse(Console.ReadLine());
- today.Print(selectedOutput);
- }
- static void DateValidation(int date, string type)
- {
- Console.WriteLine("Invalid date! {0} {1} doesn't exist.", type, date);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement