Example #1
0
        /// <summary>
        /// Evaluates a math expression of 2 time spans.
        /// </summary>
        /// <param name="node">The AST node the evaluation is a part of.</param>
        /// <param name="lhs">The time on the left hand side</param>
        /// <param name="rhs">The time on the right hand side</param>
        /// <param name="op">The math operator.</param>
        /// <returns></returns>
        public static LTime CalcDates(AstNode node, LDate lhs, LDate rhs, Operator op)
        {
            if (op != Operator.Subtract)
                throw ExceptionHelper.BuildRunTimeException(node, "Can only subtract dates");

            var left = lhs.Value;
            var right = rhs.Value;
            var result = left - right;
            return new LTime(result);
        }
Example #2
0
        private static void SetDateTime(LDate date, DateTimeKind kind, int year = -1, int month = -1, int day = -1,
                                        int hour = -1, int minute = -1, int second = -1, int millisecond = -1)
        {
            var target = date.Value;
            var dt     = kind == DateTimeKind.Utc ? target.ToUniversalTime() : target;

            year        = year == -1 ? dt.Year : year;
            month       = month == -1 ? dt.Month : month;
            day         = day == -1 ? dt.Day : day;
            hour        = hour == -1 ? dt.Hour : hour;
            minute      = minute == -1 ? dt.Minute : minute;
            second      = second == -1 ? dt.Second : second;
            millisecond = millisecond == -1 ? dt.Millisecond : millisecond;

            var finalDateTime = new DateTime(year, month, day, hour, minute, second, millisecond, kind);

            date.Value = finalDateTime;
        }
Example #3
0
 public string   ToTimeString         (LDate target) { var date = target.Value; return date.ToString("hh mm ss");                                     }
Example #4
0
 public int      GetUtcHours          (LDate target) { var date = target.Value; return date.ToUniversalTime().Hour;                                   }
Example #5
0
 public int GetMilliseconds(LDate target)
 {
     var date = target.Value; return(date.Millisecond);
 }
Example #6
0
 public int      GetHours             (LDate target) { var date = target.Value; return date.Hour;                                                     }
Example #7
0
 public int      GetSeconds           (LDate target) { var date = target.Value; return date.Second;                                                   }
Example #8
0
 /// <summary>
 /// Sets the month on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="month">The month to set</param>
 /// <param name="day">The day of the month to set</param>
 public void SetUtcMonth(LDate date, int month, int day)
 {
     SetDateTime(date, DateTimeKind.Utc, -1, month, day);
 }
Example #9
0
        private static void SetDateTime(LDate date, DateTimeKind kind, int year = -1, int month = -1, int day = -1,
            int hour = -1, int minute = -1, int second = -1, int millisecond = -1)
        {
            var target = date.Value;
            DateTime dt = kind == DateTimeKind.Utc ? target.ToUniversalTime() : target;
            year = year == -1 ? dt.Year : year;
            month = month == -1 ? dt.Month : month;
            day = day == -1 ? dt.Day : day;
            hour = hour == -1 ? dt.Hour : hour;
            minute = minute == -1 ? dt.Minute : minute;
            second = second == -1 ? dt.Second : second;
            millisecond = millisecond == -1 ? dt.Millisecond : millisecond;

            var finalDateTime = new DateTime(year, month, day, hour, minute, second, millisecond, kind);
            date.Value = finalDateTime;
        }
Example #10
0
 public int GetUtcFullYear(LDate target)
 {
     var date = target.Value; return(date.ToUniversalTime().Year);
 }
Example #11
0
 public int GetUtcHours(LDate target)
 {
     var date = target.Value; return(date.ToUniversalTime().Hour);
 }
Example #12
0
 public int GetUtcDate(LDate target)
 {
     var date = target.Value; return(date.ToUniversalTime().Day);
 }
Example #13
0
 public int GetUtcDay(LDate target)
 {
     var date = target.Value; return((int)date.ToUniversalTime().DayOfWeek);
 }
Example #14
0
 public int GetSeconds(LDate target)
 {
     var date = target.Value; return(date.Second);
 }
Example #15
0
 public int GetMonth(LDate target)
 {
     var date = target.Value; return(date.Month);
 }
Example #16
0
 public int GetMinutes(LDate target)
 {
     var date = target.Value; return(date.Minute);
 }
Example #17
0
 /// <summary>
 /// Sets the month on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="month">The month to set</param>
 /// <param name="day">The day of the month to set</param>
 public void SetMonth(LDate date, int month, int day)
 {
     SetDateTime(date, DateTimeKind.Local, -1, month, day);
 }
Example #18
0
 public int GetUtcMinutes(LDate target)
 {
     var date = target.Value; return(date.ToUniversalTime().Minute);
 }
Example #19
0
 /// <summary>
 /// Sets the milliseconds on the date
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="milliseconds">The milliseconds to set</param>
 public void SetMilliseconds(LDate date, int milliseconds)
 {
     SetDateTime(date, DateTimeKind.Local, -1, -1, -1, -1, -1, -1, milliseconds);
 }
Example #20
0
 public int GetUtcMonth(LDate target)
 {
     var date = target.Value; return(date.ToUniversalTime().Month);
 }
Example #21
0
 /// <summary>
 /// Sets the hours on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="hours">The hours to set</param>
 /// <param name="minutes">The minutes to set</param>
 /// <param name="seconds">The seconds to set</param>
 /// <param name="milliseconds">The milliseconds to set</param>
 public void SetUtcHours(LDate date, int hours, int minutes, int seconds, int milliseconds)
 {
     SetDateTime(date, DateTimeKind.Utc, -1, -1, -1, hours, minutes, seconds, milliseconds);
 }
Example #22
0
 public int GetUtcSeconds(LDate target)
 {
     var date = target.Value; return(date.ToUniversalTime().Second);
 }
Example #23
0
 public int      GetDay               (LDate target) { var date = target.Value; return (int)date.DayOfWeek;                                           }
Example #24
0
 public string ToLocaleDateString(LDate target)
 {
     var date = target.Value; return(date.ToLocalTime().ToString("ddd MMM dd yyyy"));
 }
Example #25
0
 public int      GetMinutes           (LDate target) { var date = target.Value; return date.Minute;		                                           }
Example #26
0
 public int      GetUtcMinutes        (LDate target) { var date = target.Value; return date.ToUniversalTime().Minute;                                 }
Example #27
0
 public int      GetUtcDay            (LDate target) { var date = target.Value; return (int)date.ToUniversalTime().DayOfWeek;                         }
Example #28
0
 public string   ToLocaleDateString   (LDate target) { var date = target.Value; return date.ToLocalTime().ToString("ddd MMM dd yyyy");                }
Example #29
0
 public string ToString(LDate target)
 {
     var date = target.Value; return(date.ToString("ddd MMM dd yyyy hh mm ss"));
 }
Example #30
0
 public int GetHours(LDate target)
 {
     var date = target.Value; return(date.Hour);
 }
Example #31
0
 public int      GetUtcMonth          (LDate target) { var date = target.Value; return date.ToUniversalTime().Month;                                  }
Example #32
0
 public string ToTimeString(LDate target)
 {
     var date = target.Value; return(date.ToString("hh mm ss"));
 }
Example #33
0
 public string   ToString             (LDate target) { var date = target.Value; return date.ToString("ddd MMM dd yyyy hh mm ss");                     }
Example #34
0
 public string ToUtcString(LDate target)
 {
     var date = target.Value; return(date.ToUniversalTime().ToString("ddd MMM dd yyyy hh mm ss"));
 }
Example #35
0
 public string   ToUtcString          (LDate target) { var date = target.Value; return date.ToUniversalTime().ToString("ddd MMM dd yyyy hh mm ss");   }
Example #36
0
 /// <summary>
 /// Sets the month on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="month">The month to set</param>
 /// <param name="day">The day of the month to set</param>
 public void SetMonth(LDate date, int month, int day)
 {
     SetDateTime(date, DateTimeKind.Local, -1, month, day);
 }
Example #37
0
 /// <summary>
 /// Sets the day of the month on the date
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="day">The day of the month to set</param>
 public void SetDate(LDate date, int day)
 {
     SetDateTime(date, DateTimeKind.Local, -1, -1, day);
 }
Example #38
0
 /// <summary>
 /// Sets the day of the month on the date
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="day">The day of the month to set</param>
 public void SetDate(LDate date, int day)
 {
     SetDateTime(date, DateTimeKind.Local, -1, -1, day);
 }
Example #39
0
 /// <summary>
 /// Sets the full year on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="year">The year to set</param>
 /// <param name="month">The month to set</param>
 /// <param name="day">The day of the month to set</param>
 public void SetUtcFullYear(LDate date, int year, int month, int day)
 {
     SetDateTime(date, DateTimeKind.Utc, year, month, day);
 }
Example #40
0
 /// <summary>
 /// Sets the milliseconds on the date
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="milliseconds">The milliseconds to set</param>
 public void SetMilliseconds(LDate date, int milliseconds)
 {
     SetDateTime(date, DateTimeKind.Local, -1, -1, -1, -1, -1, -1, milliseconds);
 }
Example #41
0
 /// <summary>
 /// Sets the day of the month on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="day">The day of the month to set</param>
 public void SetUtcDate(LDate date, int day)
 {
     SetDateTime(date, DateTimeKind.Utc, -1, -1, day);
 }
Example #42
0
 /// <summary>
 /// Sets the full year on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="year">The year to set</param>
 /// <param name="month">The month to set</param>
 /// <param name="day">The day of the month to set</param>
 public void SetUtcFullYear(LDate date, int year, int month, int day)
 {
     SetDateTime(date, DateTimeKind.Utc, year, month, day);
 }
Example #43
0
 /// <summary>
 /// Sets the milliseconds on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="milliseconds">The milliseconds to set</param>
 public void SetUtcMilliseconds(LDate date, int milliseconds)
 {
     SetDateTime(date, DateTimeKind.Utc, -1, -1, -1, -1, -1, -1, milliseconds);
 }
Example #44
0
 /// <summary>
 /// Sets the month on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="month">The month to set</param>
 /// <param name="day">The day of the month to set</param>
 public void SetUtcMonth(LDate date, int month, int day)
 {
     SetDateTime(date, DateTimeKind.Utc, -1, month, day);
 }
Example #45
0
 public int      GetDate              (LDate target) { var date = target.Value; return date.Day;                                                      }      	
Example #46
0
 /// <summary>
 /// Sets the day of the month on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="day">The day of the month to set</param>
 public void SetUtcDate(LDate date, int day)
 {
     SetDateTime(date, DateTimeKind.Utc, -1, -1, day);
 }
Example #47
0
 public int      GetFullYear          (LDate target) { var date = target.Value; return date.Year;                                                     }
Example #48
0
 /// <summary>
 /// Sets the hours on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="hours">The hours to set</param>
 /// <param name="minutes">The minutes to set</param>
 /// <param name="seconds">The seconds to set</param>
 /// <param name="milliseconds">The milliseconds to set</param>
 public void SetUtcHours(LDate date, int hours, int minutes, int seconds, int milliseconds)
 {
     SetDateTime(date, DateTimeKind.Utc, -1, -1, -1, hours, minutes, seconds, milliseconds);
 }
Example #49
0
 public int      GetMilliseconds      (LDate target) { var date = target.Value; return date.Millisecond;                                              }
Example #50
0
 /// <summary>
 /// Sets the milliseconds on the date.
 /// </summary>
 /// <param name="date">The LDateType to set</param>
 /// <param name="milliseconds">The milliseconds to set</param>
 public void SetUtcMilliseconds(LDate date, int milliseconds)
 {
     SetDateTime(date, DateTimeKind.Utc, -1, -1, -1, -1, -1, -1, milliseconds);
 }
Example #51
0
 public int      GetMonth             (LDate target) { var date = target.Value; return date.Month;                                                    }
Example #52
0
 public int GetDate(LDate target)
 {
     var date = target.Value; return(date.Day);
 }
Example #53
0
 public int      GetUtcDate           (LDate target) { var date = target.Value; return date.ToUniversalTime().Day;                                    }
Example #54
0
 public int GetDay(LDate target)
 {
     var date = target.Value; return((int)date.DayOfWeek);
 }
Example #55
0
 public int      GetUtcFullYear       (LDate target) { var date = target.Value; return date.ToUniversalTime().Year;                                   }
Example #56
0
 public int GetFullYear(LDate target)
 {
     var date = target.Value; return(date.Year);
 }
Example #57
0
 public int      GetUtcMilliseconds   (LDate target) { var date = target.Value; return date.ToUniversalTime().Millisecond;                            }  
Example #58
0
 /// <summary>
 /// Evaluates a math expression of 2 time spans.
 /// </summary>
 /// <param name="node">The AST node the evaluation is a part of.</param>
 /// <param name="lhs">The time on the left hand side</param>
 /// <param name="rhs">The time on the right hand side</param>
 /// <param name="op">The math operator.</param>
 /// <returns></returns>
 public static LBool CompareDates(AstNode node, LDate lhs, LDate rhs, Operator op)
 {
     var left = lhs.Value;
     var right = rhs.Value;
     var result = false;
     if (op == Operator.LessThan)             result = left < right;
     else if (op == Operator.LessThanEqual)   result = left <= right;
     else if (op == Operator.MoreThan)        result = left > right;
     else if (op == Operator.MoreThanEqual)   result = left >= right;
     else if (op == Operator.EqualEqual)      result = left == right;
     else if (op == Operator.NotEqual)        result = left != right;
     return new LBool(result);
 }