Exemplo n.º 1
0
 public static DateTimeEx GetInstance(TimeZoneInfo timeZoneInfo)
 {
     return(new DateTimeEx(
                DateTimeOffsetHelper.Now(timeZoneInfo),
                timeZoneInfo
                ));
 }
Exemplo n.º 2
0
 public DateTimeEx SetMillis(int millis)
 {
     _dateTime = DateTimeOffsetHelper.CreateDateTime(
         _dateTime.Year, _dateTime.Month, _dateTime.Day,
         _dateTime.Hour, _dateTime.Minute, _dateTime.Second,
         millis, _timeZone);
     return(this);
 }
Exemplo n.º 3
0
 public DateTimeEx SetDay(int day)
 {
     _dateTime = DateTimeOffsetHelper.CreateDateTime(
         _dateTime.Year, _dateTime.Month, day,
         _dateTime.Hour, _dateTime.Minute, _dateTime.Second,
         _dateTime.Millisecond, _timeZone);
     return(this);
 }
Exemplo n.º 4
0
 public DateTimeEx SetYear(int year)
 {
     _dateTime = DateTimeOffsetHelper.CreateDateTime(
         year, _dateTime.Month, _dateTime.Day,
         _dateTime.Hour, _dateTime.Minute, _dateTime.Second,
         _dateTime.Millisecond, _timeZone);
     return(this);
 }
Exemplo n.º 5
0
        public static string Print(this long timeInMillis, TimeZoneInfo timeZoneInfo = null)
        {
            if (timeZoneInfo == null)
            {
                timeZoneInfo = TimeZoneInfo.Local;
            }

            return(Print(DateTimeOffsetHelper.TimeFromMillis(timeInMillis, timeZoneInfo)));
        }
Exemplo n.º 6
0
        public static DateTimeOffset GetWithMaximumDay(this DateTimeOffset dateTime, TimeZoneInfo timeZone = null)
        {
            var daysInMonth = Calendar.GetDaysInMonth(dateTime.Year, dateTime.Month);

            if (timeZone == null)
            {
                return(new DateTimeOffset(
                           dateTime.Year, dateTime.Month, daysInMonth, dateTime.Hour, dateTime.Minute,
                           dateTime.Second, dateTime.Millisecond, dateTime.Offset));
            }

            return(DateTimeOffsetHelper.CreateDateTime(
                       dateTime.Year, dateTime.Month, daysInMonth, dateTime.Hour, dateTime.Minute,
                       dateTime.Second, dateTime.Millisecond, timeZone));
        }
Exemplo n.º 7
0
        public static DateTimeOffset AsDateTimeOffset(this object value, TimeZoneInfo timeZone)
        {
            if (value is DateTimeOffset dateTimeOffsetValue)
            {
                return(dateTimeOffsetValue.TranslateTo(timeZone));
            }
            if (value is DateTime dateTimeValue)
            {
                return(dateTimeValue.TranslateTo(timeZone));
            }
            if (value is long longValue)
            {
                return(DateTimeOffsetHelper.TimeFromMillis(longValue, timeZone));
            }
            if (value is int intValue)
            {
                return(DateTimeOffsetHelper.TimeFromMillis(intValue, timeZone));
            }

            throw new ArgumentException("invalid value for datetime", nameof(value));
        }
Exemplo n.º 8
0
        public static DateTimeOffset AsDateTimeOffset(this object value, TimeZoneInfo timeZone)
        {
            if (value is DateTimeOffset)
            {
                return(((DateTimeOffset)value).TranslateTo(timeZone));
            }
            if (value is DateTime)
            {
                return(((DateTime)value).TranslateTo(timeZone));
            }
            if (value is long)
            {
                return(DateTimeOffsetHelper.TimeFromMillis((long)value, timeZone));
            }
            if (value is int)
            {
                return(DateTimeOffsetHelper.TimeFromMillis((int)value, timeZone));
            }

            throw new ArgumentException("invalid value for datetime", "value");
        }
Exemplo n.º 9
0
 public DateTimeEx Set(int year, int month, int day, int hour = 0, int minute = 0, int second = 0, int millisecond = 0)
 {
     _dateTime = DateTimeOffsetHelper.CreateDateTime(
         year, month, day, hour, minute, second, millisecond, _timeZone);
     return(this);
 }
Exemplo n.º 10
0
 public DateTimeEx SetUtcMillis(long millis)
 {
     _dateTime = DateTimeOffsetHelper.TimeFromMillis(millis, _timeZone);
     return(this);
 }
Exemplo n.º 11
0
        public static DateTimeEx GetInstance(TimeZoneInfo timeZoneInfo, long timeInMillis)
        {
            var baseDt = DateTimeOffsetHelper.TimeFromMillis(timeInMillis, timeZoneInfo);

            return(new DateTimeEx(baseDt, timeZoneInfo));
        }
Exemplo n.º 12
0
        public static DateTimeEx GetInstance(TimeZoneInfo timeZoneInfo, DateTime dateTime)
        {
            var baseDt = DateTimeOffsetHelper.ToDateTimeOffset(dateTime, timeZoneInfo);

            return(new DateTimeEx(baseDt, timeZoneInfo));
        }