예제 #1
0
 public static long Diff(DatePartType datePart, DateTime dt1, DateTime dt2)
 {
     switch (datePart) {
     case DatePartType.Year:
         return dt2.Year - dt1.Year;
     case DatePartType.Quarter:
         return (dt2.Year - dt1.Year) * 4 + (dt2.Month - 1) / 3 - (dt1.Month - 1) / 3;
     case DatePartType.Month:
         return (dt2.Year - dt1.Year) * 12 + dt2.Month - dt1.Month;
     case DatePartType.Day:
     case DatePartType.DayOfYear:
     case DatePartType.DayOfWeek:
         return (dt2.Date - dt1.Date).Days;
     case DatePartType.Hour:
         return dt2.Ticks / TimeSpan.TicksPerHour - dt1.Ticks / TimeSpan.TicksPerHour;
     case DatePartType.Minute:
         return dt2.Ticks / TimeSpan.TicksPerMinute - dt1.Ticks / TimeSpan.TicksPerMinute;
     case DatePartType.Second:
         return dt2.Ticks / TimeSpan.TicksPerSecond - dt1.Ticks / TimeSpan.TicksPerSecond;
     case DatePartType.MilliSecond:
         return dt2.Ticks / TimeSpan.TicksPerMillisecond - dt1.Ticks / TimeSpan.TicksPerMillisecond;
     case DatePartType.MicroSecond:
         return dt2.Ticks / TimeSpan.TicksPerMillisecond / 1000 - dt1.Ticks / TimeSpan.TicksPerMillisecond / 1000;
     case DatePartType.NanoSecond:
         return dt2.Ticks / TimeSpan.TicksPerMillisecond / 1000000 - dt1.Ticks / TimeSpan.TicksPerMillisecond / 1000000;
     default:
         throw new InvalidOperationException (string.Format ("Unknown DatePart type '{0}'", datePart));
     }
 }
예제 #2
0
 public static DateTime Add(DatePartType datePart, long add, DateTime dt)
 {
     switch (datePart) {
     case DatePartType.Year:
         return dt.AddYears ((int)add);
     case DatePartType.Quarter:
         return dt.AddMonths ((int)add * 3);
     case DatePartType.Month:
         return dt.AddMonths ((int)add);
     case DatePartType.Day:
     case DatePartType.DayOfYear:
     case DatePartType.DayOfWeek:
         return dt.AddDays (add);
     case DatePartType.Hour:
         return dt.AddHours (add);
     case DatePartType.Minute:
         return dt.AddMinutes (add);
     case DatePartType.Second:
         return dt.AddSeconds (add);
     case DatePartType.MilliSecond:
         return dt.AddMilliseconds (add);
     case DatePartType.MicroSecond:
         return dt.AddTicks (add * TimeSpan.TicksPerMillisecond / 1000);
     case DatePartType.NanoSecond:
         return dt.AddTicks (add * TimeSpan.TicksPerMillisecond / 1000000);
     default:
         throw new InvalidOperationException (string.Format ("Unknown DatePart type '{0}'", datePart));
     }
 }
예제 #3
0
        public static string DatePart(string columnName, DatePartType partType)
        {
            StringBuilder sb = new StringBuilder("DATEPART(");

            sb.Append(partType.ToString());
            sb.Append(',');
            SqlQueryUtils.AppendColumnName(sb, columnName);
            sb.Append(')');
            return(sb.ToString());
        }
예제 #4
0
        public static string DatePart(string columnName, DatePartType partType)
        {
            Check.Require(!string.IsNullOrEmpty(columnName), "columnName could not be null or empty!");

            StringBuilder sb = new StringBuilder("DATEPART(");
            sb.Append(partType.ToString());
            sb.Append(',');
            SqlQueryUtils.AppendColumnName(sb, columnName);
            sb.Append(')');
            return sb.ToString();
        }
예제 #5
0
파일: Sql.cs 프로젝트: codeinsiders/sharpql
        public static Function DateAdd(DatePartType datePart, Expression number, Expression date)
        {
            if (number == null) {
                throw new ArgumentNullException("number");
            }

            if (date == null) {
                throw new ArgumentNullException("date");
            }

            return new DateAddFunction(datePart, number, date);
        }
        public static string DatePart(string columnName, DatePartType partType)
        {
            Check.Require(!string.IsNullOrEmpty(columnName), "columnName could not be null or empty!");

            StringBuilder sb = new StringBuilder("DATEPART(");

            sb.Append(partType.ToString());
            sb.Append(',');
            SqlQueryUtils.AppendColumnName(sb, columnName);
            sb.Append(')');
            return(sb.ToString());
        }
예제 #7
0
파일: Sql.cs 프로젝트: w0lya/sharpql
        public static Function DateAdd(DatePartType datePart, Expression number, Expression date)
        {
            if (number == null)
            {
                throw new ArgumentNullException("number");
            }

            if (date == null)
            {
                throw new ArgumentNullException("date");
            }

            return(new DateAddFunction(datePart, number, date));
        }
예제 #8
0
 public DateAddFunctionView(DatePartType type)
 {
     Type = type;
 }
예제 #9
0
 public DatePartFunction DatePart(DatePartType partType)
 {
     return(new DatePartFunction(partType, this));
 }
예제 #10
0
 public static long Get(DatePartType datePart, DateTime dt)
 {
     switch (datePart) {
     case DatePartType.Year:
         return dt.Year;
     case DatePartType.Quarter:
         return (dt.Month - 1) / 3 + 1;
     case DatePartType.Month:
         return dt.Month;
     case DatePartType.DayOfYear:
         return dt.DayOfYear;
     case DatePartType.Day:
         return dt.Day;
     case DatePartType.DayOfWeek:
         return (int)dt.DayOfWeek + 1;
     case DatePartType.Hour:
         return dt.Hour;
     case DatePartType.Minute:
         return dt.Minute;
     case DatePartType.Second:
         return dt.Second;
     case DatePartType.MilliSecond:
         return dt.Millisecond;
     case DatePartType.MicroSecond:
         return (dt.Ticks % TimeSpan.TicksPerSecond) / (TimeSpan.TicksPerMillisecond / 1000);
     case DatePartType.NanoSecond:
         return (dt.Ticks % TimeSpan.TicksPerSecond) * 1000 / (TimeSpan.TicksPerMillisecond / 1000);
     default:
         throw new InvalidOperationException (string.Format ("Unknown DatePart type '{0}'", datePart));
     }
 }
 public DateAddFunctionView(DatePartType type)
 {
     Type = type;
 }
예제 #12
0
 public DatePartFunction(DatePartType partType, IQueryValueExpression expression) : base(expression)
 {
     PartType = partType;
 }
예제 #13
0
 public DateAddFunction(DatePartType datePart, Expression number, Expression date)
 {
     this.DatePart = datePart;
     this.Number   = number;
     this.Date     = date;
 }
예제 #14
0
 public DateAddFunction(DatePartType datePart, Expression number, Expression date)
 {
     this.DatePart = datePart;
     this.Number = number;
     this.Date = date;
 }