Examples of IDateTime


Examples of org.eclipse.imp.pdb.facts.IDateTime

  }

  @Override
  public <U extends IValue> Result<U> fieldAccess(String name, TypeStore store) {
    IValueFactory vf = getValueFactory();
    IDateTime dt = getValue();

    try {

      if (name.equals("year")) {
        if (!dt.isTime()) {
          return makeResult(getTypeFactory().integerType(), vf.integer(dt.getYear()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the year on a time value",ctx.getCurrentAST());
      } else if (name.equals("month")) {
        if (!dt.isTime()) {
          return makeResult(getTypeFactory().integerType(), vf.integer(getValue().getMonthOfYear()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the month on a time value",ctx.getCurrentAST());
      } else if (name.equals("day")) {
        if (!dt.isTime()) {
          return makeResult(getTypeFactory().integerType(), vf.integer(getValue().getDayOfMonth()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the day on a time value",ctx.getCurrentAST());
      } else if (name.equals("hour")) {
        if (!dt.isDate()) {
          return makeResult(getTypeFactory().integerType(), vf.integer(getValue().getHourOfDay()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the hour on a date value",ctx.getCurrentAST());
      } else if (name.equals("minute")) {
        if (!dt.isDate()) {
          return makeResult(getTypeFactory().integerType(), vf.integer(getValue().getMinuteOfHour()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the minute on a date value",ctx.getCurrentAST());
      } else if (name.equals("second")) {
        if (!dt.isDate()) {
          return makeResult(getTypeFactory().integerType(), vf.integer(getValue().getSecondOfMinute()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the second on a date value",ctx.getCurrentAST());
      } else if (name.equals("millisecond")) {
        if (!dt.isDate()) {
          return makeResult(getTypeFactory().integerType(), vf.integer(getValue().getMillisecondsOfSecond()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the millisecond on a date value",ctx.getCurrentAST());
      } else if (name.equals("timezoneOffsetHours")) {
        if (!dt.isDate()) {
          return makeResult(getTypeFactory().integerType(), vf.integer(getValue().getTimezoneOffsetHours()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the timezone offset hours on a date value",ctx.getCurrentAST());
      } else if (name.equals("timezoneOffsetMinutes")) {
        if (!dt.isDate()) {
          return makeResult(getTypeFactory().integerType(), vf.integer(getValue().getTimezoneOffsetMinutes()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the timezone offset minutes on a date value",ctx.getCurrentAST());
      } else if (name.equals("century")) {
        if (!dt.isTime()) {
          return makeResult(getTypeFactory().integerType(), vf.integer(getValue().getCentury()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the century on a time value",ctx.getCurrentAST());
      } else if (name.equals("isDate")) {
        return makeResult(getTypeFactory().boolType(), vf.bool(getValue().isDate()), ctx);
      } else if (name.equals("isTime")) {
        return makeResult(getTypeFactory().boolType(), vf.bool(getValue().isTime()), ctx);
      } else if (name.equals("isDateTime")) {
        return makeResult(getTypeFactory().boolType(), vf.bool(getValue().isDateTime()), ctx);
      } else if (name.equals("justDate")) {
        if (!dt.isTime()) {
          return makeResult(getTypeFactory().dateTimeType(),
              vf.date(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the date component of a time value",ctx.getCurrentAST());
      } else if (name.equals("justTime")) {
        if (!dt.isDate()) {
          return makeResult(getTypeFactory().dateTimeType(),
              vf.time(dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute(),
                  dt.getMillisecondsOfSecond(), dt.getTimezoneOffsetHours(),
                  dt.getTimezoneOffsetMinutes()), ctx);
        }
        throw new UnsupportedOperation("Can not retrieve the time component of a date value",ctx.getCurrentAST());
      }
    } catch (InvalidDateTimeException e) {
      throw RuntimeExceptionFactory.illegalArgument(dt, ctx.getCurrentAST(), null, e.getMessage());
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.IDateTime

  public <U extends IValue, V extends IValue> Result<U> fieldUpdate(
      String name, Result<V> repl, TypeStore store) {
   
    Type replType = repl.getType();
    IValue replValue = repl.getValue();
    IDateTime dt = getValue();
   
    // Individual fields
    int year = dt.getYear();
    int month = dt.getMonthOfYear();
    int day = dt.getDayOfMonth();
    int hour = dt.getHourOfDay();
    int minute = dt.getMinuteOfHour();
    int second = dt.getSecondOfMinute();
    int milli = dt.getMillisecondsOfSecond();
    int tzOffsetHour = dt.getTimezoneOffsetHours();
    int tzOffsetMin = dt.getTimezoneOffsetMinutes();

    try {
      if (name.equals("year")) {
        if (dt.isTime()) {
          throw new UnsupportedOperation("Can not update the year on a time value",ctx.getCurrentAST());
        }     
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        year = ((IInteger) replValue).intValue();
      } else if (name.equals("month")) {
        if (dt.isTime()) {
          throw new UnsupportedOperation("Can not update the month on a time value",ctx.getCurrentAST());
        }     
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        month = ((IInteger) replValue).intValue();       
      } else if (name.equals("day")) {
        if (dt.isTime()) {
          throw new UnsupportedOperation("Can not update the day on a time value",ctx.getCurrentAST());
        }     
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        day = ((IInteger) replValue).intValue();       
      } else if (name.equals("hour")) {
        if (dt.isDate()) {
          throw new UnsupportedOperation("Can not update the hour on a date value",ctx.getCurrentAST());
        }     
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        hour = ((IInteger) replValue).intValue();       
      } else if (name.equals("minute")) {
        if (dt.isDate()) {
          throw new UnsupportedOperation("Can not update the minute on a date value",ctx.getCurrentAST());
        }     
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        minute = ((IInteger) replValue).intValue();       
      } else if (name.equals("second")) {
        if (dt.isDate()) {
          throw new UnsupportedOperation("Can not update the second on a date value",ctx.getCurrentAST());
        }     
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        second = ((IInteger) replValue).intValue();       
      } else if (name.equals("millisecond")) {
        if (dt.isDate()) {
          throw new UnsupportedOperation("Can not update the millisecond on a date value",ctx.getCurrentAST());
        }     
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        milli = ((IInteger) replValue).intValue();     
      } else if (name.equals("timezoneOffsetHours")) {
        if (dt.isDate()) {
          throw new UnsupportedOperation("Can not update the timezone offset hours on a date value",ctx.getCurrentAST());
        }     
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        tzOffsetHour = ((IInteger) replValue).intValue();       
      } else if (name.equals("timezoneOffsetMinutes")) {
        if (dt.isDate()) {
          throw new UnsupportedOperation("Can not update the timezone offset minutes on a date value",ctx.getCurrentAST());
        }     
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        tzOffsetMin = ((IInteger) replValue).intValue();       
      } else {
        throw new UndeclaredField(name, getTypeFactory().dateTimeType(), ctx.getCurrentAST());
      }

      IDateTime newdt = null;
      if (dt.isDate()) {
        newdt = getValueFactory().date(year, month, day);
      } else if (dt.isTime()) {
        newdt = getValueFactory().time(hour, minute, second, milli, tzOffsetHour, tzOffsetMin);
      } else {
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.IDateTime

    return that.subtractDateTime(this);
  }

  @Override
  protected <U extends IValue> Result<U> subtractDateTime(DateTimeResult that) {
    IDateTime dStart = this.getValue();
    Calendar startCal = Calendar.getInstance();
    startCal.setTimeInMillis(dStart.getInstant());

    IDateTime dEnd = that.getValue();
    Calendar endCal = Calendar.getInstance();
    endCal.setTimeInMillis(dEnd.getInstant());
   
    if (dStart.isDate()) {
      if (dEnd.isDate()) {
        return makeResult(Duration,
            VF.constructor(DateTimeResult.duration,
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.YEAR)),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.MONTH)),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.DAY_OF_MONTH)),
              VF.integer(0),
              VF.integer(0),
              VF.integer(0),
              VF.integer(0)),
            ctx);
      } else if (dEnd.isTime()) {
        throw RuntimeExceptionFactory.invalidUseOfTimeException("Cannot determine the duration between a date with no time and a time with no date.", ctx.getCurrentAST(), null)
      } else {
        throw RuntimeExceptionFactory.invalidUseOfDateTimeException("Cannot determine the duration between a date with no time and a datetime.", ctx.getCurrentAST(), null);         
      }
    } else if (dStart.isTime()) {
      if (dEnd.isTime()) {
        return makeResult(Duration,
            VF.constructor(DateTimeResult.duration,
              VF.integer(0),
              VF.integer(0),
              VF.integer(0),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.HOUR_OF_DAY)),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.MINUTE)),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.SECOND)),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.MILLISECOND))),
            ctx);
      } else if (dEnd.isDate()) {
        throw RuntimeExceptionFactory.invalidUseOfDateException("Cannot determine the duration between a time with no date and a date with no time.", ctx.getCurrentAST(), null)
      } else {
        throw RuntimeExceptionFactory.invalidUseOfDateTimeException("Cannot determine the duration between a time with no date and a datetime.", ctx.getCurrentAST(), null);         
      }
    } else {
      if (dEnd.isDateTime()) {
        return makeResult(Duration,
            VF.constructor(DateTimeResult.duration,
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.YEAR)),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.MONTH)),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.DAY_OF_MONTH)),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.HOUR_OF_DAY)),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.MINUTE)),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.SECOND)),
              VF.integer(startCal.fieldDifference(endCal.getTime(), Calendar.MILLISECOND))),
            ctx);
      } else if (dEnd.isDate()) {
        throw RuntimeExceptionFactory.invalidUseOfDateException("Cannot determine the duration between a datetime and a date with no time.", ctx.getCurrentAST(), null)
      } else {
        throw RuntimeExceptionFactory.invalidUseOfTimeException("Cannot determine the duration between a datetime and a time with no date.", ctx.getCurrentAST(), null);         
      }
    }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.IDateTime

  }

  @Override
  public Void visitDateTime(IDateTime value) throws IOException {
    // {datetime: { }}
    IDateTime dt = (IDateTime) value;
    out.beginArray();
    out.value("datetime");
    out.beginObject();
    if (dt.isDate() || dt.isDateTime()) {
      out.name("year");
      out.value(dt.getYear());
      out.name("monthOfYear");
      out.value(dt.getMonthOfYear());
      out.name("dayOfMonth");
      out.value(dt.getDayOfMonth());

    }
    if (dt.isTime() || dt.isDateTime()) {
      out.name("hourOfDay");
      out.value(dt.getHourOfDay());
      out.name("minuteOfHour");
      out.value(dt.getMinuteOfHour());
      out.name("secondOfMinute");
      out.value(dt.getSecondOfMinute());
      out.name("millisecondsOfSecond");
      out.value(dt.getMillisecondsOfSecond());
      out.name("timezoneOffsetHours");
      out.value(dt.getTimezoneOffsetHours());
      out.name("timezoneOffsetMinutes");
      out.value(dt.getTimezoneOffsetMinutes());
    }
    out.endObject();
    out.endArray();
    return null;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.