Package org.exist.xquery.value

Examples of org.exist.xquery.value.DateValue


                "Expected at most one xs:date", args[0]);
        } else if (args[1].hasMany()) {
            throw new XPathException(this, ErrorCodes.XPTY0004,
                "Expected at most one xs:time", args[1]);
        } else {
            final DateValue dv = (DateValue)args[0].itemAt(0);
            final TimeValue tv = (TimeValue)args[1].itemAt(0);
            if (!dv.getTimezone().isEmpty()) {
                if (!tv.getTimezone().isEmpty()) {
                    if (!((DayTimeDurationValue)dv.getTimezone().itemAt(0))
                        .compareTo(null, Constants.EQ,
                            ((DayTimeDurationValue)tv.getTimezone().itemAt(0)))) {
                       
                      final ValueSequence argsSeq = new ValueSequence();
                        argsSeq.add(dv);
                        argsSeq.add(tv);
                       
                        throw new XPathException(this, ErrorCodes.FORG0008,
                            "Operands have different timezones", argsSeq);
                    }
                }
            }
            String dtv = ((DateTimeValue)dv.convertTo(Type.DATE_TIME)).getTrimmedCalendar().toXMLFormat();
           
            if (dv.getTimezone().isEmpty()) {
                dtv = dtv.substring(0, dtv.length() - 8);
                result = new DateTimeValue(dtv + tv.getStringValue());
           
            } else if ("PT0S".equals(((DayTimeDurationValue)dv.getTimezone().itemAt(0)).getStringValue())) {
                dtv = dtv.substring(0, dtv.length() - 9);
                if (tv.getTimezone().isEmpty()) {
                    result = new DateTimeValue(dtv + tv.getStringValue() + "Z");
                } else {
                    result = new DateTimeValue(dtv + tv.getStringValue());
View Full Code Here


    }

    @Override
    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException
    {
        DateValue d = (DateValue)args[0].itemAt(0);
        GregorianCalendar cal = d.calendar.toGregorianCalendar();
        int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

        return new IntegerValue(days);
    }
View Full Code Here

    }

    @Override
    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException
    {
        DateValue d = (DateValue)args[0].itemAt(0);
        String dateFormat = args[1].itemAt(0).toString();

        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);

        GregorianCalendar cal = d.calendar.toGregorianCalendar();
View Full Code Here

    }

    @Override
    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException
    {
        DateValue d = (DateValue)args[0].itemAt(0);
        GregorianCalendar cal = d.calendar.toGregorianCalendar();
        int weekInMonth = cal.get(Calendar.WEEK_OF_MONTH);

        return new IntegerValue(weekInMonth);
    }
View Full Code Here

    cal.set(Calendar.YEAR, yearOfInterest);
    cal.set(Calendar.MONTH, monthOfInterest - 1);
    cal.set(Calendar.WEEK_OF_MONTH, weekInMonth);
    cal.set(Calendar.DAY_OF_WEEK, dayInWeek);
   
    return new DateValue(TimeUtils.getInstance().newXMLGregorianCalendar(cal));
  }
View Full Code Here

    super(context, signature);
  }

  @Override
  public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    DateValue d = (DateValue) args[0].itemAt(0);
    GregorianCalendar cal = d.calendar.toGregorianCalendar();
    int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);

    return new IntegerValue(dayOfWeek);
  }
View Full Code Here

            Date date = sdf.parse(strDate);

            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(date);

            return new DateValue(TimeUtils.getInstance().newXMLGregorianCalendar(cal));
        }
        catch(ParseException pe)
        {
            throw new XPathException(this, "Could not parse date string '" + strDate + "' for format '" + dateFormat + "': " + pe.getMessage(), pe);
        }
View Full Code Here

  }

  public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException
 
    int dayOfInterest = ((IntegerValue)args[0].itemAt(0)).getInt();
    DateValue d = (DateValue)args[1].itemAt(0);
   
    GregorianCalendar cal = new GregorianCalendar(Locale.getDefault());
    cal.set(Calendar.YEAR, d.getPart(DateValue.YEAR));
    cal.set(Calendar.MONTH, d.getPart(DateValue.MONTH) - 1);
    cal.set(Calendar.DAY_OF_MONTH, 1);
   
    //start on the first instance of the day in the month
    cal.set(Calendar.DAY_OF_WEEK, dayOfInterest);
   
View Full Code Here

        if (args[0].isEmpty())
            return Sequence.EMPTY_SEQUENCE;

        try {
            DateValue value = (DateValue)args[0].itemAt(0);

            String picture = FormatFunctionConstants.translate(args[1].itemAt(0).getStringValue());
            String language = (args.length <= 2 || args[2].isEmpty()) ? null : args[2].itemAt(0).getStringValue();
            String calendar = (args.length <= 2 || args[3].isEmpty()) ? null : args[3].itemAt(0).getStringValue();
            String country = (args.length <= 2 || args[4].isEmpty()) ? null : args[4].itemAt(0).getStringValue();
            SimpleDateFormat format = null;

            if (language != null || country != null) {
                Locale locale = (country == null) ? new Locale(language) : new Locale(language, country);
                format = new SimpleDateFormat(picture, locale);
            } else {
                format = new SimpleDateFormat(picture);
            }
            return new StringValue(format.format(value.toJavaObject(java.util.Date.class)));
        } catch (java.lang.IllegalArgumentException e) {
            throw new XPathException(e.getMessage());
        }
  }
View Full Code Here

    private final static Pattern DATE_REGEX = Pattern.compile("(\\d+)-(\\d+)-(\\d+)");

    @Override
    public Field toField(String fieldName, String content) {
        try {
            DateValue dv;
            if (content.indexOf('-') < 0) {
                // just year
                int year = Integer.parseInt(content);
                XMLGregorianCalendar calendar = TimeUtils.getInstance().newXMLGregorianCalendar();
                calendar.setYear(year);
                calendar.setDay(1);
                calendar.setMonth(1);
                dv = new DateValue(calendar);
            } else {
                // try to handle missing digits as in 1980-8-4
                Matcher matcher = DATE_REGEX.matcher(content);
                if (matcher.matches()) {
                    try {
                        content = String.format("%04d-%02d-%02d", Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3)));
                    } catch (NumberFormatException e) {
                        // invalid content: ignore
                    }
                }
                dv = new DateValue(content);
            }
            final long dl = RangeIndexConfigElement.dateToLong(dv);
            return new LongField(fieldName, dl, LongField.TYPE_NOT_STORED);
        } catch (XPathException e) {
            // wrong type: ignore
View Full Code Here

TOP

Related Classes of org.exist.xquery.value.DateValue

Copyright © 2018 www.massapicom. 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.