public DateRange(DateTime startTime, DateTime endTime, DateTimeTypeEnum type, DateTime epoch) { Type = type; Epoch = epoch; SetStartTime(startTime); SetEndTime(endTime); }
public DateRange(DateTimeOffset startOffset, DateTimeOffset endOffset, DateTimeTypeEnum type, DateTime epoch) { Type = type; Epoch = epoch; SetStartTime(startOffset.DateTime); SetEndTime(endOffset.DateTime); }
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; }
public DateRange(TimeSpan startSpan, TimeSpan endSpan, DateTimeTypeEnum type, DateTime epoch) { Type = type; Epoch = epoch; SetStartTime(epoch.Add(startSpan)); SetEndTime(epoch.Add(endSpan)); }
/// <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)); }
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"); } }
/// <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); }
/// <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); }
internal Datetime(DateTime datetime, DateTimeTypeEnum dateTimeType) { this._instance = datetime; this._dateTimeType = dateTimeType; }
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; }
public Datetime(int year, int month, int dayOfMonth) { this._instance = new DateTime(year, month, dayOfMonth); this._dateTimeType = DateTimeTypeEnum.date; }
public Datetime(Datetime other) { this._instance = other._instance; this._dateTimeType = other._dateTimeType; }
public Datetime(DateTime datetime) { this._instance = datetime; this._dateTimeType = DateTimeTypeEnum.both; }
public void Clear() { this._instance = new DateTime(); this._dateTimeType = DateTimeTypeEnum.neither; }
/// <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)); }
public DateTimeType(DateTimeTypeEnum type) { this.Type = type; }
public Datetime() { this._instance = new DateTime(); this._dateTimeType = DateTimeTypeEnum.neither; }
public void SetByAbsolute(string key, object content, double timer, DateTimeTypeEnum dateTimeType) { double millisecond = DateTimeManager.ToMilliseconds(timer, dateTimeType); SetByAbsolute(key, content, TimeSpan.FromMilliseconds(millisecond)); }