Example usage for org.joda.time DateTime plusMonths

List of usage examples for org.joda.time DateTime plusMonths

Introduction

In this page you can find the example usage for org.joda.time DateTime plusMonths.

Prototype

public DateTime plusMonths(int months) 

Source Link

Document

Returns a copy of this datetime plus the specified number of months.

Usage

From source file:com.todoroo.andlib.utility.DateUtilities.java

License:Open Source License

/**
 * Add the specified amount of months to the given time.<br/>
 * The day of month will stay the same.<br/>
 *
 * @param time the base-time (in milliseconds) to which the amount of months is added
 * @param interval the amount of months to be added
 * @return the calculated time in milliseconds
 *//*w ww .j a  v  a  2s  .  c o m*/
public static long addCalendarMonthsToUnixtime(long time, int interval) {
    DateTime dt = new DateTime(time);
    DateTime result = dt.plusMonths(interval);
    // preserving java.util.date behavior
    int diff = dt.getDayOfMonth() - result.getDayOfMonth();
    if (diff > 0) {
        result = result.plusDays(diff);
    }
    return result.getMillis();
}

From source file:com.toedter.jcalendar.core.DateChooser.java

License:Open Source License

private void computeDayCellValues() {
    DateTime firstDayThisMonth = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), 1, 0, 0, 0, 0);
    DateTime firstDayNextMonth = firstDayThisMonth.plusMonths(1).withDayOfMonth(1);
    int dayOfWeek = firstDayThisMonth.dayOfWeek().get();

    Days d = Days.daysBetween(firstDayThisMonth, firstDayNextMonth);
    int daysInThisMonth = d.getDays();
    System.out.println(daysInThisMonth);

    int index = 2;
    for (IDayCell dayCell : dayCells) {
        if (index <= dayOfWeek || index - dayOfWeek > daysInThisMonth) {
            ((DayCell) dayCell).dayText = "";
        } else {//from   www  .  j  a v a 2 s  .  c om
            ((DayCell) dayCell).dayText = "" + (index - dayOfWeek);
        }
        index++;
    }
}

From source file:com.webarch.common.datetime.DateTimeUtils.java

License:Apache License

/**
 * ?//w  ww  .ja v  a  2  s  . com
 *
 * @param date     ?
 * @param after    ??
 * @param timeUnit ??
 * @return ??
 */
public static Date getAfterDate(Date date, final int after, final int timeUnit) {
    DateTime dateTime = new DateTime(date);
    Date result;
    switch (timeUnit) {
    case YEAR_UNIT:
        result = dateTime.plusYears(after).toDate();
        break;
    case MONTH_UNIT:
        result = dateTime.plusMonths(after).toDate();
        break;
    case DAY_UNIT:
        result = dateTime.plusDays(after).toDate();
        break;
    case HOURE_UNIT:
        result = dateTime.plusHours(after).toDate();
        break;
    case MINUTE_UNIT:
        result = dateTime.plusMinutes(after).toDate();
        break;
    default:
        result = date;
    }
    return result;
}

From source file:de.azapps.mirakel.model.list.meta.SpecialListsDueProperty.java

License:Open Source License

@NonNull
@Override/*  w  ww  .ja va 2 s . com*/
public MirakelQueryBuilder getWhereQueryBuilder(@NonNull final Context ctx) {
    MirakelQueryBuilder qb = new MirakelQueryBuilder(ctx).and(Task.DUE, MirakelQueryBuilder.Operation.NOT_EQ,
            (String) null);
    DateTime date = new LocalDate().toDateTimeAtStartOfDay().plusDays(1).minusSeconds(10);
    Log.w(TAG, String.valueOf(date.getMillis()));
    switch (unit) {
    case DAY:
        date = date.plusDays(length);
        break;
    case MONTH:
        date = date.plusMonths(length);
        break;
    case YEAR:
        date = date.plusYears(length);
        break;
    }
    qb = qb.and(Task.DUE, isSet ? Operation.GT : Operation.LT, date.getMillis());
    Log.w(TAG, qb.toString(Task.URI));
    return qb;
}

From source file:de.zib.gndms.dspace.service.utils.DSpaceAspects.java

License:Apache License

@Around(value = "inSliceServiceImpl() && args( subspaceId, sliceKindId, sliceId, .. )")
public Object handleSlice(final ProceedingJoinPoint pjp, final String subspaceId, final String sliceKindId,
        final String sliceId) throws NoSuchElementException, Throwable {
    // check Rights
    {/*from   www . j av a  2s . c om*/
        final Slice slice = sliceProvider.getSlice(subspaceId, sliceId);

        final UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication()
                .getPrincipal();
        final String dn = userDetails.getUsername();
        final String owner = slice.getOwner();

        // TODO: check for user / group rights here
        // ATTENTION: group can be null

        if (!owner.equals(dn)) {
            logger.debug("User " + dn + " tried to access slice " + sliceId + ", owned by " + slice.getOwner()
                    + ".");
            throw new UnauthorizedException("User " + dn + " does not own slice " + sliceId + ".");
        }
    }

    Object returnvalue = pjp.proceed();

    // extend termination time, if it had been published
    {
        EntityManager entityManager = emf.createEntityManager();
        final TxFrame txf = new TxFrame(entityManager);
        try {
            final Slice slice = entityManager.find(Slice.class, sliceId);
            if (slice.getPublished()) {
                final DateTime now = new DateTime(DateTimeUtils.currentTimeMillis());
                final DateTime month = now.plusMonths(1);

                if (slice.getTerminationTime().isBefore(month)) {
                    slice.setTerminationTime(month);
                }
            }
            txf.commit();
        } finally {
            txf.finish();
        }
    }

    return returnvalue;
}

From source file:de.zib.gndms.taskflows.interslicetransfer.server.logic.InterSliceTransferTaskAction.java

License:Apache License

@Override
protected void onInProgress(@NotNull String wid, @NotNull TaskState state, boolean isRestartedTask,
        boolean altTaskState) throws Exception {

    ensureOrder();//  ww  w .  j av a 2 s .  c o m
    InterSliceTransferQuoteCalculator.prepareSourceUrl(getOrder(), sliceClient);
    prepareDestination();

    // check for quotas
    {
        final InterSliceTransferOrder order = getOrderBean();
        if (null != order.getSourceSlice() && null != order.getDestinationSpecifier()) {

            final ResponseEntity<SliceInformation> sourceSliceConfigResponse = sliceClient
                    .getSliceInformation(order.getSourceSlice(), getOrder().getDNFromContext());
            final ResponseEntity<SliceInformation> destinationSliceConfigResponse = sliceClient
                    .getSliceInformation(order.getDestinationSpecifier(), getOrder().getDNFromContext());
            final long sliceSize = destinationSliceConfigResponse.getBody().getSize();
            final long sliceUsage = destinationSliceConfigResponse.getBody().getDiskUsage();
            final long needSize = sourceSliceConfigResponse.getBody().getDiskUsage();

            if (sliceUsage + needSize > sliceSize)
                throw new IllegalStateException("Transfer would exceed slice size: Need "
                        + String.valueOf(needSize) + " Bytes but have only "
                        + String.valueOf(sliceSize - sliceUsage) + " Bytes left.");
        }
    }

    Session session = getDao().beginSession();
    final String subTaskId = getUUIDGen().nextUUID();
    try {
        final Task task = getTask(session);

        final Task st = task.createSubTask();
        st.setId(subTaskId);
        st.setPayload(null);

        st.setTerminationTime(task.getTerminationTime());
        session.success();
    } finally {
        session.finish();
    }

    session = getDao().beginSession();
    final FileTransferTaskAction fta;
    try {
        final Task task = getTask(session);

        final Task st = session.findTask(subTaskId);
        fta = new FileTransferTaskAction(getEmf().createEntityManager(), getDao(), st.getTaskling());
        getInjector().injectMembers(fta);

        fta.setCredentialProvider(getCredentialProvider());
        fta.setEmf(getEmf());

        session.success();
    } finally {
        session.finish();
    }

    fta.call();

    // extend termination time, if it had been published
    if (getOrderBean().getSourceSlice() != null) {
        final String sliceId = getOrderBean().getSourceSlice().getUriMap().get(UriFactory.SLICE);

        final TxFrame txf = new TxFrame(getEntityManager());
        try {
            final Slice slice = getEntityManager().find(Slice.class, sliceId);
            if (slice.getPublished()) {
                final DateTime now = new DateTime(DateTimeUtils.currentTimeMillis());
                final DateTime month = now.plusMonths(1);

                if (slice.getTerminationTime().isBefore(month)) {
                    slice.setTerminationTime(month);
                }
            }
            txf.commit();
        } finally {
            txf.finish();
        }
    }

    session = getDao().beginSession();
    try {
        final Task task = getTask(session);

        final Task st = session.findTask(subTaskId);
        if (st.getTaskState().equals(TaskState.FINISHED)) {
            //noinspection ConstantConditions
            final InterSliceTransferResult payload = (InterSliceTransferResult) task.getPayload();
            payload.populate((FileTransferResult) st.getPayload());
            task.setPayload(payload);
            task.setTaskState(TaskState.FINISHED);
            if (altTaskState)
                task.setAltTaskState(null);
        } else
            throw new RuntimeException("FileTransfer did not finish: ", st.getCause().getFirst());
        session.success();
    } finally {
        session.finish();
    }
}

From source file:divconq.test.Schema1.java

License:Open Source License

public static void main(String[] args) {
    try {/*w ww  .j  a va 2s. c o  m*/
        DateTime zyear3 = new DateTime(2012, 3, 15, 0, 0, 0, DateTimeZone.UTC);

        System.out.println("1: " + zyear3.plusMonths(1));
        System.out.println("5: " + zyear3.plusMonths(5));
        System.out.println("8: " + zyear3.plusMonths(8));
        System.out.println("9: " + zyear3.plusMonths(9));
        System.out.println("10: " + zyear3.plusMonths(10));
        System.out.println("11: " + zyear3.plusMonths(11));
        System.out.println("12: " + zyear3.plusMonths(12));
        System.out.println("13: " + zyear3.plusMonths(13));
        System.out.println("20: " + zyear3.plusMonths(20));
        System.out.println("21: " + zyear3.plusMonths(21));
        System.out.println("22: " + zyear3.plusMonths(22));
        System.out.println("23: " + zyear3.plusMonths(23));
        System.out.println("24: " + zyear3.plusMonths(24));
        System.out.println("30: " + zyear3.plusMonths(30));
        System.out.println("31: " + zyear3.plusMonths(31));
        System.out.println("32: " + zyear3.plusMonths(32));
        System.out.println("33: " + zyear3.plusMonths(33));
        System.out.println("34: " + zyear3.plusMonths(34));
        System.out.println("40: " + zyear3.plusMonths(40));
        System.out.println("41: " + zyear3.plusMonths(41));
        System.out.println("42: " + zyear3.plusMonths(42));
        System.out.println("43: " + zyear3.plusMonths(43));
        System.out.println("200: " + zyear3.plusMonths(200));
        System.out.println("500: " + zyear3.plusMonths(500));
        System.out.println("1000: " + zyear3.plusMonths(1000));
        System.out.println("2000: " + zyear3.plusMonths(2000));
        System.out.println("5000: " + zyear3.plusMonths(5000));
        System.out.println("7000: " + zyear3.plusMonths(7000));

        /*
        System.out.println("1: " + Schema1.dayOfWeek(0, 1, 1));
        System.out.println("1: " + Schema1.dayOfWeek(1, 1, 1));
        System.out.println("2: " + Schema1.dayOfWeek(500, 1, 1));
        System.out.println("3: " + Schema1.dayOfWeek(900, 1, 1));
        System.out.println("4: " + Schema1.dayOfWeek(1800, 1, 1));
        System.out.println("5: " + Schema1.dayOfWeek(1900, 1, 1));
        System.out.println("6: " + Schema1.dayOfWeek(2000, 1, 1));
                
                
        DateTime zyeara = new DateTime(0, 1, 1, 0, 0, 0, DateTimeZone.UTC);
        DateTime zyeara1 = new DateTime(1, 1, 1, 0, 0, 0, DateTimeZone.UTC);
        DateTime zyearb = new DateTime(500, 1, 1, 0, 0, 0, DateTimeZone.UTC);
        DateTime zyearc = new DateTime(900, 1, 1, 0, 0, 0, DateTimeZone.UTC);
        DateTime zyear1 = new DateTime(1800, 1, 1, 0, 0, 0, DateTimeZone.UTC);
        DateTime zyear2 = new DateTime(1900, 1, 1, 0, 0, 0, DateTimeZone.UTC);
        DateTime zyear3 = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeZone.UTC);
                
        System.out.println("1: " + zyeara.getDayOfWeek());
        System.out.println("1: " + zyeara1.getDayOfWeek());
        System.out.println("2: " + zyearb.getDayOfWeek());
        System.out.println("3: " + zyearc.getDayOfWeek());
        System.out.println("4: " + zyear1.getDayOfWeek());
        System.out.println("5: " + zyear2.getDayOfWeek());
        System.out.println("6: " + zyear3.getDayOfWeek());
        */

        /*
         DateTimeZone America_Los_Angeles = new DateTimeZoneBuilder()
             .addCutover(-2147483648, 'w', 1, 1, 0, false, 0)
             .setStandardOffset(-28378000)
             .setFixedSavings("LMT", 0)
             .addCutover(1883, 'w', 11, 18, 0, false, 43200000)
             .setStandardOffset(-28800000)
             .addRecurringSavings("PDT", 3600000, 1918, 1919, 'w',  3, -1, 7, false, 7200000)
             .addRecurringSavings("PST",       0, 1918, 1919, 'w', 10, -1, 7, false, 7200000)
             .addRecurringSavings("PWT", 3600000, 1942, 1942, 'w',  2,  9, 0, false, 7200000)
             .addRecurringSavings("PPT", 3600000, 1945, 1945, 'u',  8, 14, 0, false, 82800000)
             .addRecurringSavings("PST",       0, 1945, 1945, 'w',  9, 30, 0, false, 7200000)
             .addRecurringSavings("PDT", 3600000, 1948, 1948, 'w',  3, 14, 0, false, 7200000)
             .addRecurringSavings("PST",       0, 1949, 1949, 'w',  1,  1, 0, false, 7200000)
             .addRecurringSavings("PDT", 3600000, 1950, 1966, 'w',  4, -1, 7, false, 7200000)
             .addRecurringSavings("PST",       0, 1950, 1961, 'w',  9, -1, 7, false, 7200000)
             .addRecurringSavings("PST",       0, 1962, 1966, 'w', 10, -1, 7, false, 7200000)
             .addRecurringSavings("PST",       0, 1967, 2147483647, 'w', 10, -1, 7, false, 7200000)
             .addRecurringSavings("PDT", 3600000, 1967, 1973, 'w', 4, -1,  7, false, 7200000)
             .addRecurringSavings("PDT", 3600000, 1974, 1974, 'w', 1,  6,  0, false, 7200000)
             .addRecurringSavings("PDT", 3600000, 1975, 1975, 'w', 2, 23,  0, false, 7200000)
             .addRecurringSavings("PDT", 3600000, 1976, 1986, 'w', 4, -1,  7, false, 7200000)
             .addRecurringSavings("PDT", 3600000, 1987, 2147483647, 'w', 4, 1, 7, true, 7200000)
             .toDateTimeZone("America/Los_Angeles", true);         
                
        int year = 2012;
                
        //for (String id : DateTimeZone.getAvailableIDs()) {
           DateTimeZone z = DateTimeZone.forID("America/New_York");
                   
           DateTime zyear = new DateTime(year, 1, 1, 0, 0, 0, z);
                   
           System.out.println("Zone: " + z.getID());
                   
           System.out.println("   " + zyear);
                   
           //while (zyear.getYear() == year) {
              long lz = z.nextTransition(zyear.getMillis());            
              zyear = new DateTime(lz, z);
                      
              System.out.println("   " + zyear);
           //}
        //}
        */

        System.exit(0);

        OperationContext.useHubContext();

        HubResources resources = new HubResources();
        resources.setDebugLevel(DebugLevel.Info);
        OperationResult or = resources.init();

        if (or.hasErrors()) {
            Logger.error("Unable to continue, hub resources not properly initialized");
            return;
        }

        Hub.instance.start(resources);

        {
            System.out.println("Implicit Example");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Code", 5);
            ex1.setField("Message", "Problem with coolant system.");

            System.out.println("Code: " + ex1.getFieldAsString("Code"));
            long code = ex1.getFieldAsInteger("Code");

            System.out.println("Code Is Priority Level: " + (code < 3));
        }

        System.out.println("----------------");

        {
            System.out.println("Explicit Example");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Code", new IntegerStruct(5));
            ex1.setField("Message", new StringStruct("Problem with coolant system."));

            System.out.println("Code: " + ex1.getFieldAsString("Code"));
            long code = ex1.getFieldAsInteger("Code");

            System.out.println("Code Is Priority Level: " + (code < 3));
        }

        System.out.println("----------------");

        {
            System.out.println("Alternative Type Example");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Code", "5");
            ex1.setField("Message", "Problem with coolant system.");

            System.out.println("Code: " + ex1.getFieldAsString("Code"));
            long code = ex1.getFieldAsInteger("Code");

            System.out.println("Code Is Priority Level: " + (code < 3));
        }

        System.out.println("----------------");

        {
            System.out.println("List Example");

            ListStruct ex2 = new ListStruct();
            ex2.addItem(0);
            ex2.addItem(20);
            ex2.addItem(50);
            ex2.addItem(90);
            ex2.addItem(140);

            for (int i = 0; i < ex2.getSize(); i++) {
                long code = ex2.getItemAsInteger(i);
                System.out.println("Code " + code + " is priority level: " + (code < 73));
            }
        }

        System.out.println("----------------");

        {
            System.out.println("Record List Example");

            ListStruct ex3 = new ListStruct();

            RecordStruct m1 = new RecordStruct();
            m1.setField("Code", 5);
            m1.setField("Message", "Problem with coolant system.");

            ex3.addItem(m1);

            RecordStruct m2 = new RecordStruct();
            m2.setField("Code", 53);
            m2.setField("Message", "Fan blade nicked.");

            ex3.addItem(m2);

            for (int i = 0; i < ex3.getSize(); i++) {
                RecordStruct msg = ex3.getItemAsRecord(i);
                System.out.println("Message #" + i);
                System.out.println("   Code: " + msg.getFieldAsString("Code"));
                System.out.println("   Text: " + msg.getFieldAsString("Message"));
            }
        }

        System.out.println("----------------");

        {
            System.out.println("Record List Example 2");

            ListStruct ex3 = new ListStruct(
                    new RecordStruct(new FieldStruct("Code", 5),
                            new FieldStruct("Message", "Problem with coolant system.")),
                    new RecordStruct(new FieldStruct("Code", 53),
                            new FieldStruct("Message", "Fan blade nicked.")));

            for (int i = 0; i < ex3.getSize(); i++) {
                RecordStruct msg = ex3.getItemAsRecord(i);
                System.out.println("Message #" + i);
                System.out.println("   Code: " + msg.getFieldAsString("Code"));
                System.out.println("   Text: " + msg.getFieldAsString("Message"));
            }
        }

        System.out.println("----------------");

        {
            System.out.println("Schema Example 1-A");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Code", 5);
            ex1.setField("Message", "Problem with coolant system.");

            System.out.println(ex1.validate("Schema1Ex1").toString());
        }

        System.out.println("----------------");

        {
            System.out.println("Schema Example 1-B");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Code", "5");
            ex1.setField("Message", "Problem with coolant system.");

            System.out.println(ex1.validate("Schema1Ex1").toString());
        }

        System.out.println("----------------");

        {
            System.out.println("Schema Example 1-C");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Code", "abc");
            ex1.setField("Message", "Problem with coolant system.");

            System.out.println(ex1.validate("Schema1Ex1").toString());
        }

        System.out.println("----------------");

        {
            System.out.println("Schema Example 2-A");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Message", "Problem with coolant system.");

            System.out.println(ex1.validate("Schema1Ex1").toString());
        }

        System.out.println("----------------");

        {
            System.out.println("Schema Example 2-B");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Message", "Problem with coolant system.");

            System.out.println(ex1.validate("Schema1Ex2").toString());
        }

        System.out.println("----------------");

        {
            System.out.println("Schema Example 2-C");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Code", 5);
            ex1.setField("Message", "Problem with coolant system.");

            System.out.println(ex1.validate("Schema1Ex2").toString());
        }

        System.out.println("----------------");

        {
            System.out.println("Schema Example 3A");

            ListStruct ex3 = new ListStruct(
                    new RecordStruct(new FieldStruct("Code", 5),
                            new FieldStruct("Message", "Problem with coolant system.")),
                    new RecordStruct(new FieldStruct("Message", "Fan belt cracked.")),
                    new RecordStruct(new FieldStruct("Code", 53),
                            new FieldStruct("Message", "Fan blade nicked.")),
                    new RecordStruct(new FieldStruct("Code", "abc"),
                            new FieldStruct("Message", "Fan bearing worn.")));

            System.out.println(ex3.validate("Schema1Ex3").toString());
        }

        System.out.println("----------------");

        {
            System.out.println("Schema Example 3B");

            ListStruct ex3 = new ListStruct(
                    new RecordStruct(new FieldStruct("Code", 5),
                            new FieldStruct("Message", "Problem with coolant system.")),
                    new RecordStruct(new FieldStruct("Code", 52),
                            new FieldStruct("Message", "Fan belt cracked.")),
                    new RecordStruct(new FieldStruct("Code", 53),
                            new FieldStruct("Message", "Fan blade nicked.")),
                    new RecordStruct(new FieldStruct("Code", 54),
                            new FieldStruct("Message", "Fan bearing worn.")));

            System.out.println(ex3.validate("Schema1Ex3").toString());
        }

        System.out.println("----------------");

        {
            System.out.println("Schema Example 7A");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Code", 5);
            ex1.setField("Message", "Problem with coolant system.");

            System.out.println(ex1.validate("Schema1Ex7").toString());
        }

        System.out.println("----------------");

        {
            System.out.println("Schema Example 7B");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Code", 200);
            ex1.setField("Message", "Problem with coolant system.");

            System.out.println(ex1.validate("Schema1Ex7").toString());
        }

        System.out.println("----------------");

        {
            System.out.println("Schema Example 7C");

            RecordStruct ex1 = new RecordStruct();
            ex1.setField("Code", 201);
            ex1.setField("Message", "Problem with coolant system.");

            System.out.println(ex1.validate("Schema1Ex7").toString());
        }

        //System.out.println("----------------");
        //System.out.println(ex1.validate("Schema1Ex1").toString());

        /*
        // typed ResultMessage record
        RecordStruct msg1 = dcschema.newRecord("ResultMessage");
                
        System.out.println("----------------");
        System.out.println(msg1.validate().toString());
                
        msg1.setField("Level", "Info");
        msg1.setField("Code", 3);
        msg1.setField("Message", "Howday partner!");
                
        System.out.println("----------------");
        System.out.println(msg1.toString());
                
        System.out.println("----------------");
        System.out.println(msg1.validate().toString());
                
        //rec.setField("Level", "What!!");
        //rec.removeField("Code");
                
        //System.out.println("----------------");
        //System.out.println(rec.validate().toString());
                
        System.out.println("-------------------------------------------------------");
                
        // typed ResponseMessage record
        RecordStruct resp = dcschema.newRecord("ResponseMessage");
                
        System.out.println(resp.validate().toString());
                
        resp.setField("Service", "Reply");
        resp.setField("Result", 6);
                
        System.out.println("----------------");
        System.out.println(resp.toString());
                
        System.out.println("----------------");
        System.out.println(resp.validate().toString());
                
        System.out.println("-------------------------------------------------------");
                
        FuncResult<Struct> msgs = resp.getOrAllocateField("Messages"); 
                
        ((ListStruct) msgs.getResult()).addItem(msg1);
                
        System.out.println("----------------");
        System.out.println(resp.toString());
                
        System.out.println("----------------");
        System.out.println(resp.validate().toString());
                
        System.out.println("-------------------------------------------------------");
                
        // untyped record attempting to merge with typed
        RecordStruct msg2 = new RecordStruct();
                
        msg2.setField("Level", "Exit");
        msg2.setField("Code", 5);
        msg2.setField("Message", "Goodday partner!");
                
        ((ListStruct) msgs.getResult()).addItem(msg2);
                
        System.out.println("----------------");
        System.out.println(resp.toString());
                
        System.out.println("----------------");
        System.out.println(resp.validate().toString());
                
        System.out.println("-------------------------------------------------------");
        */
    } catch (Exception x) {
        System.out.println("Error in test: " + x);
    }

    Hub.instance.stop();
}

From source file:edu.nyu.vida.data_polygamy.utils.FrameworkUtils.java

License:BSD License

public static int addTimeSteps(int tempRes, int increment, DateTime start) {

    DateTime d;/*from w  w w  .  j a  va  2  s . co m*/

    switch (tempRes) {
    case FrameworkUtils.HOUR:
        d = start.plusHours(increment);
        break;
    case FrameworkUtils.DAY:
        d = start.plusDays(increment);
        break;
    case FrameworkUtils.WEEK:
        d = start.plusWeeks(increment);
        break;
    case FrameworkUtils.MONTH:
        d = start.plusMonths(increment);
        break;
    case FrameworkUtils.YEAR:
        d = start.plusYears(increment);
        break;
    default:
        d = start.plusHours(increment);
        break;
    }

    return (int) (d.getMillis() / 1000);

}

From source file:edu.nyu.vida.data_polygamy.utils.FrameworkUtils.java

License:BSD License

public static DateTime addTime(int tempRes, int increment, DateTime start) {

    DateTime d = null;/*from ww w  .  j av a2s . co m*/

    switch (tempRes) {
    case FrameworkUtils.HOUR:
        d = start.plusHours(increment);
        break;
    case FrameworkUtils.DAY:
        d = start.plusDays(increment);
        break;
    case FrameworkUtils.WEEK:
        d = start.plusWeeks(increment);
        break;
    case FrameworkUtils.MONTH:
        d = start.plusMonths(increment);
        break;
    case FrameworkUtils.YEAR:
        d = start.plusYears(increment);
        break;
    default:
        d = start.plusHours(increment);
        break;
    }

    return d;

}

From source file:graph.inference.module.LaterThanWorker.java

License:Open Source License

private Interval parseDate(DAGNode date, DateTime now) {
    String dateStr = date.toString();
    if (dateStr.equals("Now") || dateStr.equals("Now-Generally"))
        return new Interval(now.getMillis(), now.getMillis() + 1);
    if (dateStr.equals("Today-Indexical"))
        return new Interval(now.dayOfYear().roundFloorCopy(), now.dayOfYear().roundCeilingCopy());
    if (dateStr.equals("Tomorrow-Indexical")) {
        return new Interval(now.plusDays(1).dayOfYear().roundFloorCopy(),
                now.plusDays(1).dayOfYear().roundCeilingCopy());
    }/*from  w  ww  .j a va 2  s  . c  o  m*/
    if (dateStr.equals("Yesterday-Indexical")) {
        return new Interval(now.minusDays(1).dayOfYear().roundFloorCopy(),
                now.minusDays(1).dayOfYear().roundCeilingCopy());
    }
    if (dateStr.equals("TheYear-Indexical")) {
        return new Interval(now.year().roundFloorCopy(), now.year().roundCeilingCopy());
    }

    // Parse the date from the DAGNode
    String parsePattern = null;
    for (int i = DATE_PARSE_INTERVALS.length - 1; i >= 0; i--) {
        StringBuilder newPattern = new StringBuilder("(" + DATE_PARSE_INTERVALS[i]);
        if (parsePattern != null)
            newPattern.append(" " + parsePattern);
        newPattern.append(")");
        parsePattern = newPattern.toString();

        DateTimeFormatter dtf = DateTimeFormat.forPattern(parsePattern);
        try {
            DateTime dateTime = dtf.parseDateTime(dateStr);
            if (dateTime != null) {
                switch (i) {
                case 0:
                    return new Interval(dateTime.getMillis(),
                            dateTime.plusSeconds(1).minusMillis(1).getMillis());
                case 1:
                    return new Interval(dateTime.getMillis(),
                            dateTime.plusMinutes(1).minusMillis(1).getMillis());
                case 2:
                    return new Interval(dateTime.getMillis(), dateTime.plusHours(1).minusMillis(1).getMillis());
                case 3:
                    return new Interval(dateTime.getMillis(), dateTime.plusDays(1).minusMillis(1).getMillis());
                case 4:
                    return new Interval(dateTime.getMillis(),
                            dateTime.plusMonths(1).minusMillis(1).getMillis());
                case 5:
                    return new Interval(dateTime.getMillis(), dateTime.plusYears(1).minusMillis(1).getMillis());
                }
            }
        } catch (Exception e) {
        }
    }
    return null;
}