Base datetime extensions default data
Ejemplo n.º 1
0
        /// <summary>
        /// Convert date to an especific timezone
        /// </summary>
        /// <param name="date">date to convert</param>
        /// <param name="currentTimeZoneName">current date timezone name</param>
        /// <param name="destinationTimeZoneName">destination date timezone name</param>
        /// <returns>date on especific timezone</returns>
        public static DateTime ToTimezoneDate(this DateTime date, string currentTimeZoneName, string destinationTimeZoneName)
        {
            var currentTimezone     = BaseDateTimeExtensions.GetTimezoneInfo(currentTimeZoneName);
            var destinationTimezone = BaseDateTimeExtensions.GetTimezoneInfo(destinationTimeZoneName);

            return(date.ToTimezoneDate(currentTimezone, destinationTimezone));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Convert unix timestamp to date
 /// </summary>
 /// <param name="unixTimestap">unix to convert</param>
 /// <returns>datetime</returns>
 public static DateTime FromUnixTimestamp(this long unixTimestap)
 {
     try
     {
         return((new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(unixTimestap.TryParseDouble(0)));
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(BaseDateTimeExtensions.GetCurrentDateTime());
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// <para>Convert string date to datetime</para>
 /// <para>Return BaseDateTimeExtensions.GetCurrentDateTime() on error</para>
 /// </summary>
 /// <param name="strValue">string to convert</param>
 /// <param name="culture">date culture</param>
 /// <param name="dateTimeStyle">datetime style</param>
 /// <returns>datetime</returns>
 public static DateTime TryParseDate(this string strValue, CultureInfo culture, DateTimeStyles dateTimeStyle)
 {
     return(strValue.TryParseDate(BaseDateTimeExtensions.GetCurrentDateTime(), culture, dateTimeStyle));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// <para>Get the week number of a date</para>
 /// <para>Use BaseDateTimeExtensions.GetDefaultCalendarRule() as default calendar rule</para>
 /// <para>Use BaseDateTimeExtensions.GetDefaultFirstWeekDay() as first week day</para>
 /// </summary>
 /// <param name="date">Date to get week number</param>
 /// <returns>Week number or -1 when error</returns>
 public static int GetWeekNumber(this DateTime date)
 {
     return(date.GetWeekNumber(BaseDateTimeExtensions.GetDefaultCalendarRule(),
                               BaseDateTimeExtensions.GetDefaultFirstWeekDay()));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// <para>Get the week number of a date</para>
 /// <para>Use BaseDateTimeExtensions.GetDefaultCalendarRule() as default calendar rule</para>
 /// </summary>
 /// <param name="date">Date to get week number</param>
 /// <param name="firstWeekDay">First day of week</param>
 /// <returns>Week number or -1 when error</returns>
 public static int GetWeekNumber(this DateTime date, DayOfWeek firstWeekDay)
 {
     return(date.GetWeekNumber(BaseDateTimeExtensions.GetDefaultCalendarRule(), firstWeekDay));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// <para>Get the week number of a date</para>
 /// <para>Use BaseDateTimeExtensions.GetDefaultFirstWeekDay() as  first week day</para>
 /// </summary>
 /// <param name="date">Date to get week number</param>
 /// <param name="weekRule">Rule to calculate week number</param>
 /// <returns>Week number or -1 when error</returns>
 public static int GetWeekNumber(this DateTime date, CalendarWeekRule weekRule)
 {
     return(date.GetWeekNumber(weekRule, BaseDateTimeExtensions.GetDefaultFirstWeekDay()));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Convert date to an especific timezone
        /// </summary>
        /// <param name="date">date to convert</param>
        /// <param name="destinationTimeZoneName">destination date timezone name</param>
        /// <returns>date on especific timezone</returns>
        public static DateTime ToTimezoneDate(this DateTime date, string destinationTimeZoneName)
        {
            var destinationTimezone = BaseDateTimeExtensions.GetTimezoneInfo(destinationTimeZoneName);

            return(date.ToTimezoneDate(BaseDateTimeExtensions.GetDefaultTimezoneInfo(), destinationTimezone));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Convert date to an especific timezone
 /// </summary>
 /// <param name="date">date to convert</param>
 /// <param name="destinationTimeZoneInfo">destination date timezone info</param>
 /// <returns>date on especific timezone</returns>
 public static DateTime ToTimezoneDate(this DateTime date, TimeZoneInfo destinationTimeZoneInfo)
 {
     return(date.ToTimezoneDate(BaseDateTimeExtensions.GetDefaultTimezoneInfo(), destinationTimeZoneInfo));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Convert date to unix timestamp
        /// </summary>
        /// <param name="date">date to convert</param>
        /// <returns>unix timestamp</returns>
        public static long ToUnixTimestamp(this DateTime date)
        {
            var timezoneInfo = BaseDateTimeExtensions.GetDefaultTimezoneInfo();

            return(date.ToUnixTimestamp(timezoneInfo));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Convert date to unix timestamp
        /// </summary>
        /// <param name="date">date to convert</param>
        /// <param name="timezoneName">current date timezone name</param>
        /// <returns>unix timestamp</returns>
        public static long ToUnixTimestamp(this DateTime date, string timezoneName)
        {
            var timezoneInfo = BaseDateTimeExtensions.GetTimezoneInfo(timezoneName);

            return(date.ToUnixTimestamp(timezoneInfo));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Convert date to UtcDate
        /// </summary>
        /// <param name="date">date to convert</param>
        /// <returns>utc date</returns>
        public static DateTime ToUtc(this DateTime date)
        {
            var timezoneInfo = BaseDateTimeExtensions.GetDefaultTimezoneInfo();

            return(date.ToUtc(timezoneInfo));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Convert date to UtcDate
        /// </summary>
        /// <param name="date">date to convert</param>
        /// <param name="timezoneName">current date timezone name</param>
        /// <returns>utc date</returns>
        public static DateTime ToUtc(this DateTime date, string timezoneName)
        {
            var timezoneInfo = BaseDateTimeExtensions.GetTimezoneInfo(timezoneName);

            return(date.ToUtc(timezoneInfo));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Test if string value is a valid date value
 /// </summary>
 /// <param name="strValue">string value</param>
 /// <returns>true/false</returns>
 public static bool IsValidDate(this string strValue)
 {
     return(strValue.IsValidDate(
                BaseDateTimeExtensions.GetCurrentCulture(),
                BaseDateTimeExtensions.GetDefaultToDateDateTimeStyles()));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Convert nullable date to datetime
 /// </summary>
 /// <param name="nullableDate">nullable date to convert</param>
 /// <returns>datetime</returns>
 public static DateTime TryParseDate(this DateTime?nullableDate)
 {
     return(nullableDate.TryParseDate(BaseDateTimeExtensions.GetCurrentDateTime()));
 }