Exemplo n.º 1
0
 /// <summary>
 /// Converts datetime to time string
 /// </summary>
 /// <param name="time">The time to convert</param>
 /// <returns>The string converted time</returns>
 public static string ConvertDateTime_TimeString(DateTime time)
 {
     return(string.Format(
                "{0}:{1}:{2} {3}",
                (time.Hour == 0 || time.Hour > 12 ? Math.Abs(time.Hour - 12) : time.Hour).ToString().PadLeft(2, '0'),
                time.Minute.ToString().PadLeft(2, '0'),
                time.Second.ToString().PadLeft(2, '0'),
                time.Hour > 12 ? TimeAndDateGlobals.GetTimeOfDay(12) : TimeAndDateGlobals.GetTimeOfDay(0)
                ));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Converts datetime to a time object
 /// </summary>
 /// <param name="time">The datetime time</param>
 /// <returns>The converted time</returns>
 public static Time ConvertDateTime_Time(DateTime time)
 {
     return(new Time
     {
         Hours = time.Hour == 0 || time.Hour > 12 ? Math.Abs(time.Hour - 12) : time.Hour,
         Minutes = time.Minute,
         Seconds = time.Second,
         TimeofDay = time.Hour > 12 ? TimeAndDateGlobals.GetTimeOfDay(12) : TimeAndDateGlobals.GetTimeOfDay(0)
     });
 }
Exemplo n.º 3
0
 /// <summary>
 /// Converts a datetime into a date object
 /// </summary>
 /// <param name="date">The date</param>
 /// <returns>A date object</returns>
 public static Date ConvertDateTime_Date(DateTime date)
 {
     return(new Date
     {
         DayOfWeek = TimeAndDateGlobals.GetDayOfTheWeek((int)date.DayOfWeek),
         Month = TimeAndDateGlobals.GetMonth(date.Month),
         Day = date.Day,
         Year = date.Year
     });
 }
Exemplo n.º 4
0
        /// <summary>
        /// Converts a Date and Time object into a DateTime object
        /// </summary>
        /// <param name="date">The date</param>
        /// <returns>A datetime object</returns>
        public static DateTime ConvertDate_DateTime(Date date)
        {
            DateTime newDate = new DateTime(
                date.Year,
                (int)TimeAndDateGlobals.GetMonth(date.Month),
                date.Day
                );

            return(newDate);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Converts a DateTime to a DateTime
        /// </summary>
        /// <param name="dateTime">The date to convert</param>
        /// <returns>A DateAndTime object</returns>
        public static DateAndTime ConvertDateTime_DateAndTime(DateTime dateTime)
        {
            Date date = ConvertDateTime_Date(dateTime);
            Time time = ConvertDateTime_Time(dateTime) ?? new Time {
                Hours = 12, Minutes = 0, Seconds = 0, TimeofDay = TimeAndDateGlobals.GetTimeOfDay((int)TimeOfDay.AM)
            };

            DateAndTime dateAndTime = new DateAndTime(date, time);

            return(dateAndTime);
        }
Exemplo n.º 6
0
        /// <summary>
        /// The current time object
        /// </summary>
        /// <returns>The current time</returns>
        public static Time GetCurrentTime()
        {
            DateTime now = DateTime.Now;

            return(new Time
            {
                Hours = now.Hour == 0 || now.Hour > 12 ? Math.Abs(now.Hour - 12) : now.Hour,
                Minutes = now.Minute,
                Seconds = now.Second,
                TimeofDay = now.Hour > 12 ? TimeAndDateGlobals.GetTimeOfDay(12) : TimeAndDateGlobals.GetTimeOfDay(0)
            });
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the current date
        /// </summary>
        /// <returns>The current date object</returns>
        public static Date GetCurrentDate()
        {
            DateTime now = DateTime.Now;

            return(new Date
            {
                Month = TimeAndDateGlobals.GetMonth(now.Month),
                Day = now.Day,
                Year = now.Year,
                DayOfWeek = now.DayOfWeek.ToString()
            });
        }
Exemplo n.º 8
0
        /// <summary>
        /// The current string time
        /// </summary>
        /// <returns>The current time</returns>
        public static string GetCurrentTimeString()
        {
            DateTime now = DateTime.Now;

            return(string.Format(
                       "{0}:{1}:{2} {3}",
                       now.Hour == 0 || now.Hour > 12 ? Math.Abs(now.Hour - 12) : now.Hour,
                       now.Minute.ToString().PadLeft(2, '0'),
                       now.Second.ToString().PadLeft(2, '0'),
                       now.Hour > 12 ? TimeAndDateGlobals.GetTimeOfDay(12) : TimeAndDateGlobals.GetTimeOfDay(0)
                       ));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Converts a datetime into a date string
        /// </summary>
        /// <param name="date">The date</param>
        /// <returns>The date string</returns>
        public static string ConvertDateTime_String(DateTime date, bool shorten = false)
        {
            string dateString = shorten
                ? string.Format(
                "{0} / {1} / {2}",
                (int)TimeAndDateGlobals.GetMonth(TimeAndDateGlobals.GetMonth(date.Month)),
                date.Day,
                date.Year
                )
                : string.Format(
                "{0}, {1} {2}, {3}",
                TimeAndDateGlobals.GetDayOfTheWeek((int)date.DayOfWeek),
                TimeAndDateGlobals.GetMonth(date.Month),
                date.Day,
                date.Year
                );

            return(dateString);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Converts a Date and Time object into a DateTime object
        /// </summary>
        /// <param name="date">The date</param>
        /// <param name="time">The time</param>
        /// <returns>A datetime object</returns>
        public static DateTime ConvertDateAndTime_DateTime(DateAndTime dateAndTime)
        {
            Date date = dateAndTime.Date;
            Time time = dateAndTime.Time;

            DateTime newDate = new DateTime(
                date.Year,
                (int)TimeAndDateGlobals.GetMonth(date.Month),
                date.Day,
                time == null ? 0 : time.Hours,
                time == null ? 0 : time.Minutes,
                time == null ? 0 : time.Seconds
                );

            newDate = time == null ?
                      newDate :
                      (TimeAndDateGlobals.GetTimeOfDay(time.TimeofDay) == 0 && time.Hours == 12 ?
                       newDate.AddHours(-12) : (TimeAndDateGlobals.GetTimeOfDay(time.TimeofDay) == 0 ?
                                                newDate : newDate.AddHours(12)));

            return(newDate);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Converts a datetime into a date string
        /// </summary>
        /// <param name="date">The date</param>
        /// <returns>The date string</returns>
        public static string ConvertDate_String(Date date, bool shorten = false)
        {
            string dateString = string.Empty;

            if (date != null)
            {
                dateString = shorten
                ? string.Format(
                    "{0} / {1} / {2}",
                    (int)TimeAndDateGlobals.GetMonth(date.Month),
                    date.Day,
                    date.Year
                    )
                : string.Format(
                    "{0}, {1} {2}, {3}",
                    date.DayOfWeek,
                    date.Month,
                    date.Day,
                    date.Year
                    );
            }

            return(dateString);
        }