svyDateUtils duration issue - solved

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

svyDateUtils duration issue - solved

Postby drookwood » Wed Nov 28, 2018 1:36 pm

I was trying to use svyDateutils to replace functionality of the dateUtils plugin, specifically here to get the end date of a duration. So I create a duration:
Code: Select all
var vDuration = scopes.svyDateUtils.createDurationFromDates(globals.search_date1,globals.search_date2)
and then want to get the end date from a different start date using the duration to calculate the end date:
Code: Select all
var vDurationEndDate = vDuration.getEndOfDuration(globals.var_date1)

This however fails with this exception:
Exception Object: org.mozilla.javascript.EvaluatorException: Can't find method java.util.GregorianCalendar.add(number,org.mozilla.javascript.Undefined)

Looking through svyDateUtils.js it seems there are a couple of omissions in the code. Changing this
Code: Select all
this.getEndOfDuration = function(startDate) {
      calendar.setTimeInMillis(startDate.getTime());
        if (this.negative) {
           calendar.add(java.util.Calendar.WEEK_OF_YEAR, -weeks);
           calendar.add(java.util.Calendar.DAY_OF_WEEK, -days);
           calendar.add(java.util.Calendar.HOUR_OF_DAY, -hours);
           calendar.add(java.util.Calendar.MINUTE, -minutes);
           calendar.add(java.util.Calendar.SECOND, -seconds);
        }
        else {
           calendar.add(java.util.Calendar.WEEK_OF_YEAR, weeks);
           calendar.add(java.util.Calendar.DAY_OF_WEEK, days);
           calendar.add(java.util.Calendar.HOUR_OF_DAY, hours);
           calendar.add(java.util.Calendar.MINUTE, minutes);
           calendar.add(java.util.Calendar.SECOND, seconds);
        }
        return new Date(calendar.getTimeInMillis());
   }
to this
Code: Select all
this.getEndOfDuration = function(startDate) {
      calendar.setTimeInMillis(startDate.getTime());
        if (this.negative) {
           calendar.add(java.util.Calendar.WEEK_OF_YEAR, -this.weeks);
           calendar.add(java.util.Calendar.DAY_OF_WEEK, -this.days);
           calendar.add(java.util.Calendar.HOUR_OF_DAY, -this.hours);
           calendar.add(java.util.Calendar.MINUTE, -this.minutes);
           calendar.add(java.util.Calendar.SECOND, -this.seconds);
        }
        else {
           calendar.add(java.util.Calendar.WEEK_OF_YEAR, this.weeks);
           calendar.add(java.util.Calendar.DAY_OF_WEEK, this.days);
           calendar.add(java.util.Calendar.HOUR_OF_DAY, this.hours);
           calendar.add(java.util.Calendar.MINUTE, this.minutes);
           calendar.add(java.util.Calendar.SECOND, this.seconds);
        }
        return new Date(calendar.getTimeInMillis());
   }
fixes it.
David Rookwood

SAN Developer
drookwood
 
Posts: 290
Joined: Tue Nov 11, 2003 7:08 pm
Location: Somerset, UK

Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests