Example #1
0
 public DateRange(DateTime startTime, DateTime endTime, DateTimeTypeEnum type, DateTime epoch)
 {
     Type  = type;
     Epoch = epoch;
     SetStartTime(startTime);
     SetEndTime(endTime);
 }
Example #2
0
 public DateRange(DateTimeOffset startOffset, DateTimeOffset endOffset, DateTimeTypeEnum type, DateTime epoch)
 {
     Type  = type;
     Epoch = epoch;
     SetStartTime(startOffset.DateTime);
     SetEndTime(endOffset.DateTime);
 }
Example #3
0
        public Datetime(int hour, int minute, int second, int milliSecond)
        {
            DateTime dtToday = DateTime.Today;

            this._instance     = new DateTime(dtToday.Year, dtToday.Month, dtToday.Day, hour, minute, second, milliSecond);
            this._dateTimeType = DateTimeTypeEnum.time;
        }
Example #4
0
 public DateRange(TimeSpan startSpan, TimeSpan endSpan, DateTimeTypeEnum type, DateTime epoch)
 {
     Type  = type;
     Epoch = epoch;
     SetStartTime(epoch.Add(startSpan));
     SetEndTime(epoch.Add(endSpan));
 }
Example #5
0
        /// <summary>
        /// 获得一个阻塞锁
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="timeout">过期时间</param>
        /// <param name="timeoutType"></param>
        /// <returns></returns>
        public async Task <RedisLock> GetBlockingLockAsync(string key, int timeout, DateTimeTypeEnum timeoutType)
        {
            var milliseconds = Convert.ToInt64(DateTimeManager.ToMilliseconds(timeout, timeoutType));
            var expiry       = new TimeSpan(milliseconds * 10000);

            return(await GetBlockingLockAsync(key, expiry));
        }
Example #6
0
        private static string GetFormatKey(DateTimeTypeEnum dateTimeType)
        {
            switch (dateTimeType)
            {
            case DateTimeTypeEnum.Week: return("%Y-%m-%d");

            case DateTimeTypeEnum.Month: return("%Y-%m-1");

            case DateTimeTypeEnum.Year: return("%Y-1-1");

            default: return("%Y-%m-%d");
            }
        }
Example #7
0
        /// <summary>
        /// 转换为秒
        /// </summary>
        /// <param name="timeValue"></param>
        /// <param name="dateTimeType"></param>
        /// <returns></returns>
        public static double ToSeconds(double timeValue, DateTimeTypeEnum dateTimeType)
        {
            var result = 0d;

            switch (dateTimeType)
            {
            case DateTimeTypeEnum.Year:
                result = timeValue * 365 * 24 * 60 * 60;
                break;

            case DateTimeTypeEnum.Month:
                result = timeValue * 30 * 24 * 60 * 60;
                break;

            case DateTimeTypeEnum.Day:
                result = timeValue * 24 * 60 * 60;
                break;

            case DateTimeTypeEnum.Hour:
                result = timeValue * 60 * 60;
                break;

            case DateTimeTypeEnum.Minute:
                result = timeValue * 60;
                break;

            case DateTimeTypeEnum.Second:
                result = timeValue;
                break;

            case DateTimeTypeEnum.Millisecond:
                result = timeValue / 1000;
                break;
            }
            return(result);
        }
Example #8
0
        /// <summary>
        /// 转换为年
        /// </summary>
        /// <param name="timeValue"></param>
        /// <param name="dateTimeType"></param>
        /// <returns></returns>
        public static double ToYear(double timeValue, DateTimeTypeEnum dateTimeType)
        {
            var result = 0d;

            switch (dateTimeType)
            {
            case DateTimeTypeEnum.Year:
                result = timeValue;
                break;

            case DateTimeTypeEnum.Month:
                result = timeValue / 12;
                break;

            case DateTimeTypeEnum.Day:
                result = timeValue / 365;
                break;

            case DateTimeTypeEnum.Hour:
                result = timeValue / 365 / 30 / 24;
                break;

            case DateTimeTypeEnum.Minute:
                result = timeValue / 365 / 30 / 24 / 60;
                break;

            case DateTimeTypeEnum.Second:
                result = timeValue / 365 / 30 / 24 / 60 / 60;
                break;

            case DateTimeTypeEnum.Millisecond:
                result = timeValue / 365 / 30 / 24 / 60 / 60 / 1000;
                break;
            }
            return(result);
        }
Example #9
0
 internal Datetime(DateTime datetime, DateTimeTypeEnum dateTimeType)
 {
     this._instance = datetime;
     this._dateTimeType = dateTimeType;
 }
Example #10
0
 public Datetime(int year, int month, int dayOfMonth, int hour, int minute, int second, int milliSecond)
 {
     this._instance = new DateTime(year, month, dayOfMonth, hour, minute, second, milliSecond);
     this._dateTimeType = DateTimeTypeEnum.both;
 }
Example #11
0
 public Datetime(int hour, int minute, int second, int milliSecond)
 {
     DateTime dtToday = DateTime.Today;
     this._instance = new DateTime(dtToday.Year, dtToday.Month, dtToday.Day, hour, minute, second, milliSecond);
     this._dateTimeType = DateTimeTypeEnum.time;
 }
Example #12
0
 public Datetime(int year, int month, int dayOfMonth)
 {
     this._instance = new DateTime(year, month, dayOfMonth);
     this._dateTimeType = DateTimeTypeEnum.date;
 }
Example #13
0
 public Datetime(Datetime other)
 {
     this._instance = other._instance;
     this._dateTimeType = other._dateTimeType;
 }
Example #14
0
 public Datetime(DateTime datetime)
 {
     this._instance     = datetime;
     this._dateTimeType = DateTimeTypeEnum.both;
 }
Example #15
0
 public void Clear()
 {
     this._instance = new DateTime();
     this._dateTimeType = DateTimeTypeEnum.neither;
 }
Example #16
0
 public void Clear()
 {
     this._instance     = new DateTime();
     this._dateTimeType = DateTimeTypeEnum.neither;
 }
Example #17
0
        /// <summary>
        /// 设置String值
        /// </summary>
        /// <param name="collectionName">集合名称</param>
        /// <param name="timeValue">时间点</param>
        /// <param name="dateTimeType"></param>
        /// <returns></returns>
        public async Task <bool> SetExpiryAsync(string collectionName, int timeValue, DateTimeTypeEnum dateTimeType)
        {
            var milliseconds = Convert.ToInt64(DateTimeManager.ToMilliseconds(timeValue, dateTimeType));
            var expiry       = new TimeSpan(milliseconds * 10000);

            return(await SetExpiryAsync(collectionName, expiry));
        }
Example #18
0
 public Datetime(int year, int month, int dayOfMonth, int hour, int minute, int second, int milliSecond)
 {
     this._instance     = new DateTime(year, month, dayOfMonth, hour, minute, second, milliSecond);
     this._dateTimeType = DateTimeTypeEnum.both;
 }
Example #19
0
 internal Datetime(DateTime datetime, DateTimeTypeEnum dateTimeType)
 {
     this._instance     = datetime;
     this._dateTimeType = dateTimeType;
 }
Example #20
0
 public Datetime(int year, int month, int dayOfMonth)
 {
     this._instance     = new DateTime(year, month, dayOfMonth);
     this._dateTimeType = DateTimeTypeEnum.date;
 }
Example #21
0
 public Datetime(Datetime other)
 {
     this._instance     = other._instance;
     this._dateTimeType = other._dateTimeType;
 }
Example #22
0
 public DateTimeType(DateTimeTypeEnum type)
 {
     this.Type = type;
 }
Example #23
0
 public Datetime()
 {
     this._instance = new DateTime();
     this._dateTimeType = DateTimeTypeEnum.neither;
 }
Example #24
0
 public Datetime(DateTime datetime)
 {
     this._instance = datetime;
     this._dateTimeType = DateTimeTypeEnum.both;
 }
Example #25
0
        public void SetByAbsolute(string key, object content, double timer, DateTimeTypeEnum dateTimeType)
        {
            double millisecond = DateTimeManager.ToMilliseconds(timer, dateTimeType);

            SetByAbsolute(key, content, TimeSpan.FromMilliseconds(millisecond));
        }
Example #26
0
 public Datetime()
 {
     this._instance     = new DateTime();
     this._dateTimeType = DateTimeTypeEnum.neither;
 }