Example usage for org.joda.time DateTime plus

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

Introduction

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

Prototype

public DateTime plus(ReadablePeriod period) 

Source Link

Document

Returns a copy of this datetime with the specified period added.

Usage

From source file:kr.debop4j.timeperiod.TimeCalendar.java

License:Apache License

@Override
public DateTime mapEnd(final DateTime moment) {
    shouldNotBeNull(moment, "moment");
    return moment.compareTo(TimeSpec.MaxPeriodTime) < 0 ? moment.plus(endOffset) : moment;
}

From source file:kr.debop4j.timeperiod.TimePeriodChain.java

License:Apache License

/**
 * {@link ITimePeriod}? Chain? index ? item? .  Period  Period?  ? ?.
 *
 * @param index  //from  ww w  .  j  a  va2  s  . c  o  m
 * @param item   
 */
@Override
public void add(int index, ITimePeriod item) {
    shouldNotBeNull(item, "item");
    shouldBeInRange(index, 0, size(), "index");
    Times.assertMutable(item);

    log.trace("Chain? ??[{}]?  [{}] ...", index, item);

    Duration itemDuration = item.getDuration();
    ITimePeriod prevItem = null;
    ITimePeriod nextItem = null;

    if (size() > 0) {
        log.trace("?  ?  ...");
        if (index > 0) {
            prevItem = get(index - 1);
            assertSpaceAfter(getEnd(), itemDuration);
        }
        if (index < size() - 1) {
            nextItem = get(index);
            assertSpaceBefore(getStart(), itemDuration);
        }
    }

    getPeriods().add(index, item);

    if (prevItem != null) {

        log.trace(
                " period?   period  period? ? ...");

        item.setup(prevItem.getEnd(), prevItem.getEnd().plus(itemDuration));

        for (int i = index + 1; i < size(); i++) {
            ITimePeriod p = get(i);
            DateTime startTime = p.getStart().plus(itemDuration);
            p.setup(startTime, startTime.plus(p.getDuration()));
        }
    }

    if (nextItem != null) {

        log.trace(
                " period?   period  period? ? ...");

        DateTime nextStart = nextItem.getStart().minus(itemDuration);
        item.setup(nextStart, nextStart.plus(itemDuration));

        for (int i = 0; i < index - 1; i++) {
            ITimePeriod p = get(i);
            nextStart = p.getStart().minus(itemDuration);
            p.setup(nextStart, nextStart.plus(p.getDuration()));
        }
    }
}

From source file:kr.debop4j.timeperiod.TimePeriodChain.java

License:Apache License

/**   , ? ITimePeriod ? ? . ( ?) */
@Override/*from w ww  .  ja  v a2  s  .c om*/
public boolean remove(Object o) {
    shouldNotBeNull(o, "o");
    shouldBe(o instanceof ITimePeriod, "o is not ITimePeriod type. class=[%s]", o.getClass());

    if (size() <= 0)
        return false;

    ITimePeriod item = (ITimePeriod) o;

    log.trace(" [{}] ? ...", item);

    Duration itemDuration = item.getDuration();
    int index = indexOf(item);

    ITimePeriod next = null;
    if (itemDuration.getMillis() > 0 && index >= 0 && index < size() - 1)
        next = get(index);

    boolean removed = getPeriods().remove(item);

    if (removed && next != null) {
        log.trace("[{}] , chain? ? periods ? ? ...",
                item);

        for (int i = index; i < size(); i++) {
            DateTime start = get(i).getStart().minus(itemDuration);
            get(i).setup(start, start.plus(get(i).getDuration()));
        }
    }

    log.trace("[{}]  =[{}]", item, removed);

    return removed;
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**  ??   ?? ? */
public static DateTime from(DateTime moment, Duration duration) {
    return moment.plus(duration);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**  ??   ?? ? */
public static DateTime since(DateTime moment, Duration duration) {
    return moment.plus(duration);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Adjust period./*from w  w  w  . ja  v  a  2  s. c om*/
 *
 * @param start    the start
 * @param duration the duration
 * @return the pair
 */
public static Pair<DateTime, Duration> adjustPeriod(DateTime start, Duration duration) {
    shouldNotBeNull(start, "start");
    shouldNotBeNull(duration, "duration");
    return (duration.getMillis() < 0) ? Pair.create(start.plus(duration), new Duration(-duration.getMillis()))
            : Pair.create(start, duration);
}

From source file:liqui.droid.service.SyncService.java

License:Apache License

public static boolean updateNeeded(Context context, String databaseName, String table, long syncTime) {
    /*/*from  ww w. j av  a  2s  .  c  o m*/
    if ("event".equals(table)) {
    println("needs update: " + table);
    return true;
    }*/

    String selection = "name = ?";
    String[] selectionArgs = new String[] { table };

    Uri uri = DBProvider.UPDATED_CONTENT_URI.buildUpon().appendQueryParameter("db", databaseName).build();
    Cursor cursor = context.getContentResolver().query(uri, null, selection, selectionArgs,
            "updated DESC LIMIT 1");

    long updated = -1;

    try {
        if (!cursor.moveToFirst()) {
            updated = 1;
        } else if (cursor.getCount() == 0) {
            updated = 0;
        } else {
            updated = cursor.getLong(1);
        }
    } finally {
        cursor.close();
    }

    // println("updated " + table + " " + updated);

    DateTime now = DateTime.now();
    DateTime t = new DateTime(updated);
    boolean before = t.plus(syncTime).isBefore(now);

    if (updated == 0 || updated == 1 || before) {
        println("needs update: " + table);
        return true;
    } else {
        println("needs no update (last update " + (-t.getMillis() + now.getMillis()) / 1000 + " seconds ago): "
                + table);
        return false;
    }
}

From source file:main.MessagesService.java

License:Apache License

public Map<String, Object> getEventsInfoFromDB(HttpServletRequest request, boolean reset) {

    ///////////////////////////////////////////////////////
    /*EventsInfo dumbEventsInfo =  new EventsInfo();
    dumbEventsInfo.Id = 1;//from   ww  w  . jav  a 2s  .c  o  m
    dumbEventsInfo.NOD_Alerts = 1;
            
            
    dumbEventsInfo.TimeStamp = DateTime.parse("2014-07-15 22:53:37.010", DateTimeFormat.forPattern(Utils.TimeFormat));
             
    dumbEventsInfo.TransactionsProcessed = 810;
    dumbEventsInfo.TotalAlerts = 90;
    dumbEventsInfo.UTF_Alerts = 0;
    dumbEventsInfo.EB1_Alerts = 2;
    dumbEventsInfo.EB2_Alerts = 1;
    dumbEventsInfo.NOD_Alerts = 4;
    dumbEventsInfo.OD1_Alerts = 4;
    dumbEventsInfo.OD2_Alerts = 14;
    dumbEventsInfo.OD3_Alerts = 22;
    dumbEventsInfo.LB_Alerts = 43;
    dumbEventsInfo.EndToEndLatency = 128641;
    dumbEventsInfo.EngineLatencyForAlerts = 99;
            
    PreviousEventsInfo = dumbEventsInfo;*/
    ////////////////////////////////////////////////////

    HttpSession session = request.getSession(true);
    EventsInfo PreviousEventsInfo = (EventsInfo) session.getAttribute("PreviousEventsInfo");
    AlertInfo LastAlert = (AlertInfo) session.getAttribute("LastAlert");
    long TimeOffsetMillis = 0;

    if (reset) {
        //dataReset(request);

        PreviousEventsInfo = null;
        LastAlert = null;
        session.setAttribute("PreviousEventsInfo", PreviousEventsInfo);
        session.setAttribute("LastAlert", LastAlert);

    }

    if (!reset)
        if (session.getAttribute("TimeOffsetMillis") != null)
            TimeOffsetMillis = (long) session.getAttribute("TimeOffsetMillis");

    ClientEventsInfo clientEventsInfo = new ClientEventsInfo();
    List<ClientAlertInfo> alertInfoList = new LinkedList<ClientAlertInfo>();

    EventsInfo eventsInfo = null;
    String pdQuery = "";
    /*if(PreviousEventsInfo == null && !reset)//we are done here
    {
       eventsInfo = null;
       clientEventsInfo = null;
    }*/

    //else
    {
        String condition = "";
        if (PreviousEventsInfo != null)
            condition = " where " + DataServices.PD_COLNAME_TimeStamp + ">'"
                    + PreviousEventsInfo.TimeStamp.minus(TimeOffsetMillis).toString(Utils.TimeFormat) + "'";

        pdQuery = "select * from " + DataServices.PD_TBL_NAME + condition + " order by "
                + DataServices.PD_COLNAME_TimeStamp + " desc limit 1";

    }

    ResultSet rs;

    Connection dbcon = null;
    try {
        dbcon = DataServices.connectToDB(getDataConnectionString());

        if (!Utils.isStringNullOrEmpty(pdQuery)) {
            //System.out.println(DateTime.now().toString(Utils.TimeFormat) + " running query: "+pdQuery);

            rs = DataServices.getResultSet(dbcon, pdQuery);
            if (rs.next()) {
                DateTime recordTimestamp = new DateTime(rs.getTimestamp(DataServices.PD_COLNAME_TimeStamp));

                if (reset) // first row
                {
                    DateTime systemTimestamp = DateTime.now();//.withZone(DateTimeZone.UTC);
                    TimeOffsetMillis = systemTimestamp.getMillis() - recordTimestamp.getMillis();
                    System.out.println("setting TimeOffsetMillis=" + TimeOffsetMillis);
                    session.setAttribute("TimeOffsetMillis", TimeOffsetMillis);
                }

                eventsInfo = new EventsInfo();
                eventsInfo.Id = rs.getLong(DataServices.PD_COLNAME_ID);
                eventsInfo.NodeId = rs.getInt(DataServices.PD_COLNAME_NodeId);
                eventsInfo.TimeStamp = recordTimestamp.plus(TimeOffsetMillis);

                eventsInfo.TransactionsProcessed = rs.getLong(DataServices.PD_COLNAME_EventsProcessed);
                eventsInfo.TotalAlerts = rs.getLong(DataServices.PD_COLNAME_Total_Alerts);
                eventsInfo.UTF_Alerts = rs.getLong(DataServices.PD_COLNAME_UTF_Alerts);
                eventsInfo.EB1_Alerts = rs.getLong(DataServices.PD_COLNAME_EB1_Alerts);
                eventsInfo.EB2_Alerts = rs.getLong(DataServices.PD_COLNAME_EB2_Alerts);
                eventsInfo.NOD_Alerts = rs.getLong(DataServices.PD_COLNAME_NOD_Alerts);
                eventsInfo.OD1_Alerts = rs.getLong(DataServices.PD_COLNAME_OD1_Alerts);
                eventsInfo.OD2_Alerts = rs.getLong(DataServices.PD_COLNAME_OD2_Alerts);
                eventsInfo.OD3_Alerts = rs.getLong(DataServices.PD_COLNAME_OD3_Alerts);
                eventsInfo.LB_Alerts = rs.getLong(DataServices.PD_COLNAME_LB_Alets);
                eventsInfo.EndToEndLatency = rs.getLong(DataServices.PD_COLNAME_EventsLatency);
                eventsInfo.EngineLatencyForAlerts = rs.getLong(DataServices.PD_COLNAME_AlertsLatency);

            } else {
                eventsInfo = null;
                clientEventsInfo = null;

            }

            rs.close();
        }

        if (eventsInfo != null) {
            clientEventsInfo = new ClientEventsInfo(eventsInfo);
            if (PreviousEventsInfo != null) {
                //int duration = Seconds.secondsBetween(PreviousEventsInfo.TimeStamp, eventsInfo.TimeStamp).getSeconds();
                double durationInSecsonds = (eventsInfo.TimeStamp.getMillis()
                        - PreviousEventsInfo.TimeStamp.getMillis()) / 1000.0;

                if (durationInSecsonds > 0) {
                    clientEventsInfo.TransactionsPerSecond = (long) ((eventsInfo.TransactionsProcessed
                            - PreviousEventsInfo.TransactionsProcessed) / durationInSecsonds);
                    clientEventsInfo.AlertsPerSecond = (long) ((eventsInfo.TotalAlerts
                            - PreviousEventsInfo.TotalAlerts) / durationInSecsonds);
                } else {
                    clientEventsInfo.TransactionsPerSecond = 0;
                    clientEventsInfo.AlertsPerSecond = 0;
                }

                clientEventsInfo.EndToEndLatency = ((eventsInfo.EndToEndLatency
                        - PreviousEventsInfo.EndToEndLatency)
                        / (eventsInfo.TransactionsProcessed - PreviousEventsInfo.TransactionsProcessed))
                        / 1000.0;
            } else {
                clientEventsInfo.TransactionsPerSecond = 0;
                clientEventsInfo.AlertsPerSecond = 0;
            }
        }

        //alerts
        String alertCondition = "";
        if (LastAlert != null)
            alertCondition += " where " + DataServices.Alert_COLNAME_TimeStamp + ">'"
                    + LastAlert.TimeStamp.minus(TimeOffsetMillis) + "'";

        String alertsQuery = "select * from " + DataServices.Alert_TBL_NAME + alertCondition;

        //System.out.println(DateTime.now().toString(Utils.TimeFormat) + " running alertsQuery: "+alertsQuery);

        rs = DataServices.getResultSet(dbcon, alertsQuery);
        if (rs.next()) {
            do {
                AlertInfo alertInfo = new AlertInfo();
                alertInfo.AlertType = rs.getString(DataServices.Alert_COLNAME_AlertType);
                alertInfo.MobileNumber = rs.getString(DataServices.Alert_COLNAME_MobileNumber);
                alertInfo.TimeStamp = new DateTime(rs.getTimestamp(DataServices.Alert_COLNAME_TimeStamp))
                        .plus(TimeOffsetMillis);
                alertInfo.AlertText = "Hi";
                alertInfo.Balance = rs.getFloat(DataServices.Alert_COLNAME_RunLedgerAmount);
                alertInfo.MessagePostTimeStamp = new DateTime(
                        rs.getTimestamp(DataServices.Alert_COLNAME_MsgPostTimeStamp)).plus(TimeOffsetMillis);
                alertInfo.AlertPostTimeStamp = new DateTime(
                        rs.getTimestamp(DataServices.Alert_COLNAME_AlertPostTimeStamp)).plus(TimeOffsetMillis);

                alertInfo.AlertLatency = (alertInfo.MessagePostTimeStamp.getMillis()
                        - alertInfo.AlertPostTimeStamp.getMillis()) / 1000.0;

                alertInfoList.add(new ClientAlertInfo(alertInfo));

                LastAlert = alertInfo;
            } while (rs.next());
        }
        rs.close();

        if (dbcon != null)
            DataServices.closeConnection(dbcon);
    } catch (Exception ex) {

    }

    Map<String, Object> result = new LinkedHashMap<String, Object>();
    result.put("EventsInfo", clientEventsInfo);
    result.put("Alerts", alertInfoList);

    if (eventsInfo != null) {
        PreviousEventsInfo = eventsInfo;//caching
        session.setAttribute("PreviousEventsInfo", PreviousEventsInfo);
    }

    session.setAttribute("LastAlert", LastAlert);

    return result;
}

From source file:main.MessagesService.java

License:Apache License

public Map<String, Object> getEventsInfoFromDB2(HttpServletRequest request, boolean reset,
        DateTime callTimestamp) {//from   w ww.  j  a  v a  2s. co  m
    HttpSession session = request.getSession(true);

    System.out.println("getEventsInfoFromDB2 requested session id=" + request.getRequestedSessionId());
    System.out.println("sessionid=" + session.getId());

    if (!session.getId().equalsIgnoreCase(request.getRequestedSessionId()))
        reset = true;

    EventsInfo PreviousEventsInfo = (EventsInfo) session.getAttribute("PreviousEventsInfo");
    AlertInfo LastAlert = (AlertInfo) session.getAttribute("LastAlert");

    long TimeOffsetMillis = 0;

    System.out.println("value from sesion=" + (session.getAttribute("TimeOffsetMillis2") == null ? "null"
            : session.getAttribute("TimeOffsetMillis2").toString()));

    if (reset) {
        //dataReset(request);

        PreviousEventsInfo = null;
        LastAlert = null;
        session.setAttribute("PreviousEventsInfo", PreviousEventsInfo);
        session.setAttribute("LastAlert", LastAlert);

    }

    //if(!reset)
    if (session.getAttribute("TimeOffsetMillis2") != null)
        TimeOffsetMillis = (long) session.getAttribute("TimeOffsetMillis2");

    System.out.println("TimeOffsetMillis2=" + TimeOffsetMillis);

    ClientEventsInfo clientEventsInfo = new ClientEventsInfo();
    List<ClientAlertInfo> alertInfoList = new LinkedList<ClientAlertInfo>();

    EventsInfo eventsInfo = null;
    String pdQuery = "";
    if (session.getAttribute("TimeOffsetMillis2") == null && !reset) {
        if (PreviousEventsInfo != null) {
            pdQuery = "select * from " + DataServices.PD_TBL_NAME + " where " + DataServices.PD_COLNAME_ID + ">"
                    + PreviousEventsInfo.Id + " order by " + DataServices.PD_COLNAME_TimeStamp + " asc limit 1";
        }

    }

    else {
        if (reset) {
            pdQuery = "select * from " + DataServices.PD_TBL_NAME + " order by "
                    + DataServices.PD_COLNAME_TimeStamp + " asc limit 1";
        } else {
            String condition = " where ";
            if (PreviousEventsInfo != null)
                condition += DataServices.PD_COLNAME_TimeStamp + ">'"
                        + PreviousEventsInfo.TimeStamp.minus(TimeOffsetMillis).toString(Utils.TimeFormat)
                        + "' and ";

            condition += DataServices.PD_COLNAME_TimeStamp + "<='"
                    + callTimestamp.minus(TimeOffsetMillis).toString(Utils.TimeFormat) + "' ";

            pdQuery = "select * from " + DataServices.PD_TBL_NAME + condition + " order by "
                    + DataServices.PD_COLNAME_TimeStamp + " desc limit 1";
        }

    }

    ResultSet rs;

    Connection dbcon = null;
    try {

        dbcon = DataServices.connectToDB(getDataConnectionString());

        if (!Utils.isStringNullOrEmpty(pdQuery)) {
            System.out.println(DateTime.now().toString(Utils.TimeFormat) + " running pdQuery: " + pdQuery);

            rs = DataServices.getResultSet(dbcon, pdQuery);
            if (rs.next()) {
                DateTime recordTimestamp = new DateTime(rs.getTimestamp(DataServices.PD_COLNAME_TimeStamp));

                if (reset || TimeOffsetMillis == 0) // first row
                {
                    DateTime systemTimestamp = callTimestamp;//.withZone(DateTimeZone.UTC);
                    TimeOffsetMillis = systemTimestamp.getMillis() - recordTimestamp.getMillis();
                    System.out.println("setting TimeOffsetMillis=" + TimeOffsetMillis);
                    session.setAttribute("TimeOffsetMillis2", TimeOffsetMillis);
                }

                eventsInfo = new EventsInfo();
                eventsInfo.Id = rs.getLong(DataServices.PD_COLNAME_ID);
                eventsInfo.NodeId = rs.getInt(DataServices.PD_COLNAME_NodeId);
                eventsInfo.TimeStamp = recordTimestamp.plus(TimeOffsetMillis);

                eventsInfo.TransactionsProcessed = rs.getLong(DataServices.PD_COLNAME_EventsProcessed);
                eventsInfo.TotalAlerts = rs.getLong(DataServices.PD_COLNAME_Total_Alerts);
                eventsInfo.UTF_Alerts = rs.getLong(DataServices.PD_COLNAME_UTF_Alerts);
                eventsInfo.EB1_Alerts = rs.getLong(DataServices.PD_COLNAME_EB1_Alerts);
                eventsInfo.EB2_Alerts = rs.getLong(DataServices.PD_COLNAME_EB2_Alerts);
                eventsInfo.NOD_Alerts = rs.getLong(DataServices.PD_COLNAME_NOD_Alerts);
                eventsInfo.OD1_Alerts = rs.getLong(DataServices.PD_COLNAME_OD1_Alerts);
                eventsInfo.OD2_Alerts = rs.getLong(DataServices.PD_COLNAME_OD2_Alerts);
                eventsInfo.OD3_Alerts = rs.getLong(DataServices.PD_COLNAME_OD3_Alerts);
                eventsInfo.LB_Alerts = rs.getLong(DataServices.PD_COLNAME_LB_Alets);
                eventsInfo.EndToEndLatency = rs.getLong(DataServices.PD_COLNAME_EventsLatency);
                eventsInfo.EngineLatencyForAlerts = rs.getLong(DataServices.PD_COLNAME_AlertsLatency);

            } else {
                eventsInfo = null;
                clientEventsInfo = null;

            }

            rs.close();
        }

        if (eventsInfo != null) {
            clientEventsInfo = new ClientEventsInfo(eventsInfo);
            if (PreviousEventsInfo != null) {
                //int duration = Seconds.secondsBetween(PreviousEventsInfo.TimeStamp, eventsInfo.TimeStamp).getSeconds();
                double durationInSecsonds = (eventsInfo.TimeStamp.getMillis()
                        - PreviousEventsInfo.TimeStamp.getMillis()) / 1000.0;

                if (durationInSecsonds > 0) {
                    clientEventsInfo.TransactionsPerSecond = (long) ((eventsInfo.TransactionsProcessed
                            - PreviousEventsInfo.TransactionsProcessed) / durationInSecsonds);
                    clientEventsInfo.AlertsPerSecond = (long) ((eventsInfo.TotalAlerts
                            - PreviousEventsInfo.TotalAlerts) / durationInSecsonds);
                } else {
                    clientEventsInfo.TransactionsPerSecond = 0;
                    clientEventsInfo.AlertsPerSecond = 0;
                }

                clientEventsInfo.EndToEndLatency = ((eventsInfo.EndToEndLatency
                        - PreviousEventsInfo.EndToEndLatency)
                        / (eventsInfo.TransactionsProcessed - PreviousEventsInfo.TransactionsProcessed))
                        / 1000.0;
            } else {
                clientEventsInfo.TransactionsPerSecond = 0;
                clientEventsInfo.AlertsPerSecond = 0;
            }
        }

        //alerts

        /*String alertCondition = "";
        DateTime nowTS = DateTime.now();
        if(LastAlert != null)
         alertCondition = " where " + DataServices.Alert_COLNAME_TimeStamp + ">'" + LastAlert.TimeStamp.minus(TimeOffsetMillis).toString(Utils.TimeFormat)+"' and ";
        else 
         alertCondition = " where ";
                
        alertCondition += DataServices.Alert_COLNAME_TimeStamp + "<='" + DateTime.now().minus(TimeOffsetMillis).toString(Utils.TimeFormat) + "'";;
                
        String alertsQuery = "select * from " + DataServices.Alert_TBL_NAME + alertCondition;
                
        System.out.println(DateTime.now().toString(Utils.TimeFormat) + " running alertsQuery: "+alertsQuery);
                
        rs = DataServices.getResultSet(dbcon, alertsQuery);
        if (rs.next())
        {
         do
         {
            AlertInfo alertInfo = new AlertInfo();
            alertInfo.AlertType = rs.getString(DataServices.Alert_COLNAME_AlertType);
            alertInfo.MobileNumber = rs.getString(DataServices.Alert_COLNAME_MobileNumber);
            alertInfo.TimeStamp = new DateTime(rs.getTimestamp(DataServices.Alert_COLNAME_TimeStamp)).plus(TimeOffsetMillis);
            alertInfo.AlertText = "Hi";
            alertInfo.Balance = rs.getFloat(DataServices.Alert_COLNAME_RunLedgerAmount);
            alertInfo.MessagePostTimeStamp = new DateTime(rs.getTimestamp(DataServices.Alert_COLNAME_MsgPostTimeStamp)).plus(TimeOffsetMillis);
            alertInfo.AlertPostTimeStamp = new DateTime(rs.getTimestamp(DataServices.Alert_COLNAME_AlertPostTimeStamp)).plus(TimeOffsetMillis);
                    
            alertInfo.AlertLatency = 
             (alertInfo.MessagePostTimeStamp.getMillis() - alertInfo.AlertPostTimeStamp.getMillis()) / 1000.0;
                    
            alertInfoList.add(new ClientAlertInfo(alertInfo));
                    
            LastAlert = alertInfo;
         }while(rs.next());
        }
        rs.close();*/

        if (dbcon != null)
            DataServices.closeConnection(dbcon);
    } catch (Exception ex) {

    }

    Map<String, Object> result = new LinkedHashMap<String, Object>();
    result.put("EventsInfo", clientEventsInfo);
    result.put("Alerts", alertInfoList);

    if (eventsInfo != null) {
        PreviousEventsInfo = eventsInfo;//caching
        session.setAttribute("PreviousEventsInfo", PreviousEventsInfo);
    }

    session.setAttribute("LastAlert", LastAlert);

    if (TimeOffsetMillis != 0)
        session.setAttribute("TimeOffsetMillis2", TimeOffsetMillis);

    System.out.println("leaving method getEventsInfoFromDB2 with session value="
            + session.getAttribute("TimeOffsetMillis2"));
    System.out.println("------------------------------------------------------------------");

    return result;
}

From source file:mobi.daytoday.DayToDay.DateWrap.java

License:Apache License

/**
 * Add the number of days to the date and return the result
 * //from   w w  w . j a v  a2 s .com
 * @param theDate
 *          - date in DATE_FORMAT format
 * @param numDays
 *          - number of days to add (may be negative for subtraction)
 * @return result of the addition in DATE_FORMAT format
 * @throws Exception
 *           - if there is any error
 */
public static String addToDate(String theDate, int numDays) throws Exception {
    DateTime date = dtForm.parseDateTime(theDate);
    Duration days = standardDays(numDays);

    DateTime result = date.plus(days);
    DateTimeFormatter MonthDayYearFormat = new DateTimeFormatterBuilder().appendMonthOfYear(1)
            .appendLiteral('-').appendDayOfMonth(1).appendLiteral('-').appendYear(4, 4).toFormatter();

    return MonthDayYearFormat.print(result);
}