Example usage for org.joda.time DateTime getDayOfMonth

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

Introduction

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

Prototype

public int getDayOfMonth() 

Source Link

Document

Get the day of month field value.

Usage

From source file:com.esri.ges.solutions.processor.geometry.QueryProcessor.java

License:Apache License

@Override
public GeoEvent process(GeoEvent ge) throws Exception {
    CreateQueryMap();/*  w ww  .  j av  a 2  s.  com*/
    double radius = (Double) properties.get("radius").getValue();
    String units = properties.get("units").getValue().toString();
    int inwkid = (Integer) properties.get("wkidin").getValue();
    int outwkid = (Integer) properties.get("wkidout").getValue();
    int bufferwkid = (Integer) properties.get("wkidbuffer").getValue();
    srIn = SpatialReference.create(inwkid);
    srBuffer = SpatialReference.create(bufferwkid);
    srOut = SpatialReference.create(outwkid);
    com.esri.ges.spatial.Point eventGeo = (com.esri.ges.spatial.Point) ge.getGeometry();
    double x = eventGeo.getX();
    double y = eventGeo.getY();
    com.esri.ges.spatial.Geometry buffer = constructBuffer(x, y, radius, units);
    String jsonGeo = buffer.toJson();
    String geotype = GeometryUtility.parseGeometryType(buffer.getType());
    ExecuteRestQueries(jsonGeo, geotype);
    String timestamp = "";
    if ((Boolean) properties.get("usetimestamp").getValue()) {
        String eventfld = properties.get("timestamp").getValueAsString();
        String[] arr = eventfld.split(":");
        timestamp = ge.getField(arr[1]).toString();
    }
    DateTime dt = DateTime.now();
    String ts = ((Integer) dt.getYear()).toString() + ((Integer) dt.getMonthOfYear()).toString()
            + ((Integer) dt.getDayOfMonth()).toString() + ((Integer) dt.getHourOfDay()).toString()
            + ((Integer) dt.getMinuteOfHour()).toString() + ((Integer) dt.getSecondOfMinute()).toString();
    String file = properties.get("filename").getValueAsString() + ts + ".html";

    ParseResponses(timestamp, file);
    String host = properties.get("host").getValueAsString();
    String url = "http://" + host + ":6180/geoevent/assets/reports/" + file;
    GeoEventDefinition geoDef = ge.getGeoEventDefinition();
    List<FieldDefinition> fds = Arrays
            .asList(((FieldDefinition) new DefaultFieldDefinition("url", FieldType.String)));
    GeoEventDefinition edOut = geoDef.augment(fds);
    edOut.setOwner(getId());
    manager.addTemporaryGeoEventDefinition(edOut, true);
    GeoEventCreator geoEventCreator = messaging.createGeoEventCreator();
    GeoEvent geOut = geoEventCreator.create(edOut.getGuid(), new Object[] { ge.getAllFields(), url });
    geOut.setProperty(GeoEventPropertyName.TYPE, "message");
    geOut.setProperty(GeoEventPropertyName.OWNER_ID, getId());
    geOut.setProperty(GeoEventPropertyName.OWNER_ID, definition.getUri());
    for (Map.Entry<GeoEventPropertyName, Object> property : ge.getProperties())
        if (!geOut.hasProperty(property.getKey()))
            geOut.setProperty(property.getKey(), property.getValue());
    queries.clear();
    responseMap.clear();
    return geOut;

}

From source file:com.esri.ges.solutions.processor.geometry.QueryReportProcessor.java

License:Apache License

@Override
public GeoEvent process(GeoEvent ge) throws Exception {
    CreateQueryMap();/*from  w  w  w.j  a  v  a  2 s  .  c o m*/
    double radius = (Double) properties.get("radius").getValue();
    String units = properties.get("units").getValue().toString();
    int inwkid = (Integer) properties.get("wkidin").getValue();
    int outwkid = (Integer) properties.get("wkidout").getValue();
    int bufferwkid = (Integer) properties.get("wkidbuffer").getValue();
    srIn = SpatialReference.create(inwkid);
    srBuffer = SpatialReference.create(bufferwkid);
    srOut = SpatialReference.create(outwkid);

    Geometry geo = ge.getGeometry();

    Geometry inGeo = null;
    if (properties.get("geosrc").getValueAsString().equals("Buffer")) {
        inGeo = constructBuffer(geo, radius, units);
    } else if (properties.get("geosrc").getValueAsString().equals("Event Definition")) {

        String eventfld = properties.get("geoeventdef").getValue().toString();
        String[] arr = eventfld.split(":");
        String geostr = (String) ge.getField(arr[1]);
        inGeo = constructGeometryFromString(geostr);
    } else {
        inGeo = geo;
    }
    String jsonGeo = inGeo.toJson();
    String geotype = GeometryUtility.parseGeometryType(inGeo.getType());
    ExecuteRestQueries(jsonGeo, geotype);
    String timestamp = "";
    if ((Boolean) properties.get("usetimestamp").getValue()) {
        String eventfld = properties.get("timestamp").getValueAsString();
        String[] arr = eventfld.split(":");
        timestamp = ge.getField(arr[1]).toString();
    }
    DateTime dt = DateTime.now();
    String ts = ((Integer) dt.getYear()).toString() + ((Integer) dt.getMonthOfYear()).toString()
            + ((Integer) dt.getDayOfMonth()).toString() + ((Integer) dt.getHourOfDay()).toString()
            + ((Integer) dt.getMinuteOfHour()).toString() + ((Integer) dt.getSecondOfMinute()).toString();
    String file = properties.get("filename").getValueAsString() + ts + ".html";

    ParseResponses(timestamp, file);
    String host = properties.get("host").getValueAsString();
    String url = "http://" + host + ":6180/geoevent/assets/reports/" + file;
    GeoEventDefinition geoDef = ge.getGeoEventDefinition();
    List<FieldDefinition> fds = Arrays
            .asList(((FieldDefinition) new DefaultFieldDefinition("url", FieldType.String)));
    GeoEventDefinition edOut = geoDef.augment(fds);
    edOut.setOwner(getId());
    manager.addTemporaryGeoEventDefinition(edOut, true);
    GeoEventCreator geoEventCreator = messaging.createGeoEventCreator();
    GeoEvent geOut = geoEventCreator.create(edOut.getGuid(), new Object[] { ge.getAllFields(), url });
    geOut.setProperty(GeoEventPropertyName.TYPE, "message");
    geOut.setProperty(GeoEventPropertyName.OWNER_ID, getId());
    geOut.setProperty(GeoEventPropertyName.OWNER_ID, definition.getUri());
    for (Map.Entry<GeoEventPropertyName, Object> property : ge.getProperties())
        if (!geOut.hasProperty(property.getKey()))
            geOut.setProperty(property.getKey(), property.getValue());
    queries.clear();
    responseMap.clear();
    return geOut;

}

From source file:com.example.android.sunshine.wear.Utility.java

License:Apache License

static public String getDayMonthDateYear(Context context, DateTime dateTime) {
    String dayName = dateTime.dayOfWeek().getAsText();
    String monthName = dateTime.monthOfYear().getAsText();
    int date = dateTime.getDayOfMonth();
    int year = dateTime.getYear();
    dayName = dayName.substring(0, 2);/* w w w.  j a va  2 s.c  o m*/
    return context.getString(R.string.datetime_display_1, dayName, monthName, date, year);

}

From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java

License:Open Source License

/** Convert millis to a date in the given timezone and then {@link #encodeDate(long, long, long)}. */
public static int encodeDate(long millis, String tz) {
    DateTime dt = new DateTime(millis, DateTimeZone.forID(tz));
    return encodeDate(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth());
}

From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java

License:Open Source License

/** Decode {@code encodedTimestamp} using the {@code tz} timezone. */
public static long[] decodeTimestamp(long encodedTimestamp, String tz) {
    DateTime dt = new DateTime(encodedTimestamp * 1000L, DateTimeZone.forID(tz));
    return new long[] { dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), dt.getHourOfDay(),
            dt.getMinuteOfHour(), dt.getSecondOfMinute() };
}

From source file:com.getusroi.wms20.parcel.parcelservice.stamps.service.StampsRateServiceBuilder.java

/**
 * this is to get the currentDate in string format to process the current
 * date in Stamps append/*from w  w  w .j a va2s  . c  o m*/
 * 
 * @return string form of date ~(YYYY-MM-DD)
 */
private static String getCurrentDateString() {

    org.joda.time.DateTime dateTime_Utc = new DateTime(DateTimeZone.UTC);
    int monthUTC = dateTime_Utc.getMonthOfYear();
    String month;
    switch (monthUTC) {
    case 1:
        month = "01";
        break;
    case 2:
        month = "02";
        break;
    case 3:
        month = "03";
        break;
    case 4:
        month = "04";
        break;
    case 5:
        month = "05";
        break;
    case 6:
        month = "06";
        break;
    case 7:
        month = "07";
        break;
    case 8:
        month = "08";
        break;
    case 9:
        month = "09";
        break;
    default:
        month = Integer.toString(monthUTC);
        break;
    }
    String dateToString = dateTime_Utc.getYear() + "-" + month + "-" + dateTime_Utc.getDayOfMonth();
    return dateToString;
}

From source file:com.github.autermann.matlab.value.MatlabDateTime.java

License:Open Source License

public double[] toArray() {
    DateTime utc = time.toDateTime(DateTimeZone.UTC);
    return new double[] { (double) utc.getYear(), (double) utc.getMonthOfYear(), (double) utc.getDayOfMonth(),
            (double) utc.getHourOfDay(), (double) utc.getMinuteOfHour(),
            (double) utc.getSecondOfMinute() + (double) utc.getMillisOfSecond() / 1000, };

}

From source file:com.google.android.apps.paco.NonESMSignalGenerator.java

License:Open Source License

private DateTime scheduleMonthly(DateTime now) {
    DateTime nowMidnight = now.toDateMidnight().toDateTime();

    if (schedule.getByDayOfMonth()) {
        int nowDOM = nowMidnight.getDayOfMonth();
        if (nowDOM == schedule.getDayOfMonth()) {
            DateTime nextTimeToday = getNextTimeToday(now, nowMidnight);
            if (nextTimeToday != null) {
                return nextTimeToday;
            }//from   www.  jav a 2 s .  c  o  m
        }
        DateTime nextDay = getNextScheduleDay(nowMidnight.plusDays(1));
        return getFirstScheduledTimeOnDay(nextDay);
    } else {
        DateTime nextDay = getNextScheduleDay(nowMidnight);
        if (nextDay.equals(nowMidnight)) {
            DateTime nextTimeToday = getNextTimeToday(now, nextDay);
            if (nextTimeToday != null) {
                return nextTimeToday;
            }
            nextDay = getNextScheduleDay(nowMidnight.plusDays(1));
            return getFirstScheduledTimeOnDay(nextDay);
        } else {
            return getFirstScheduledTimeOnDay(nextDay);
        }
    }
}

From source file:com.google.android.apps.paco.NonESMSignalGenerator.java

License:Open Source License

private DateTime getNextScheduleDay(DateTime midnightTomorrow) {

    switch (schedule.getScheduleType()) {
    case SignalSchedule.DAILY:
        return nextRepeatDaily(midnightTomorrow);

    case SignalSchedule.WEEKDAY:
        int tomorrowDOW = midnightTomorrow.getDayOfWeek();
        if (tomorrowDOW > DateTimeConstants.FRIDAY) {
            return midnightTomorrow.plusDays(8 - tomorrowDOW);
        } else {//from   ww  w  .  j  a v  a2 s .c o m
            return midnightTomorrow;
        }

    case SignalSchedule.WEEKLY:
        int scheduleDays = schedule.getWeekDaysScheduled();
        if (scheduleDays == 0) {
            return null;
        }
        for (int i = 0; i < 8; i++) { // go at least to the same day next week.
            int midnightTomorrowDOW = midnightTomorrow.getDayOfWeek();
            Integer nowDowIndex = SignalSchedule.DAYS_OF_WEEK[midnightTomorrowDOW == 7 ? 0
                    : midnightTomorrowDOW]; // joda is 1 based & counts Monday as first day of the week so Sunday is 7 instead of 0.
            if ((scheduleDays & nowDowIndex) == nowDowIndex) {
                return nextRepeatWeekly(midnightTomorrow);
            }
            midnightTomorrow = midnightTomorrow.plusDays(1);

        }
        throw new IllegalStateException("Cannot get to here. Weekly must repeat at least once a week");

    case SignalSchedule.MONTHLY:
        if (schedule.getByDayOfMonth()) {
            int midnightDOM = midnightTomorrow.getDayOfMonth();
            int scheduledDOM = schedule.getDayOfMonth();
            if (midnightDOM == scheduledDOM) {
                return midnightTomorrow;
            } else if (midnightDOM > scheduledDOM) {
                MutableDateTime mutableDateTime = midnightTomorrow.plusMonths(1).toMutableDateTime();
                mutableDateTime.setDayOfMonth(scheduledDOM);
                return nextRepeatMonthly(mutableDateTime.toDateTime());
            } else {
                return nextRepeatMonthly(midnightTomorrow.plusDays(scheduledDOM - midnightDOM));
            }
        } else {
            Integer nthOfMonth = schedule.getNthOfMonth();
            Integer dow = getDOWFromIndexedValue(); // only one selection, so take log2 to get index of dow
            DateMidnight nthDowDate = getNthDOWOfMonth(midnightTomorrow, nthOfMonth, dow).toDateMidnight();
            DateTime returnDate = null;
            if (nthDowDate.equals(midnightTomorrow)) {
                returnDate = midnightTomorrow;
            } else if (nthDowDate.isAfter(midnightTomorrow)) {
                returnDate = nthDowDate.toDateTime();
            } else {
                returnDate = getNthDOWOfMonth(midnightTomorrow.plusMonths(1), nthOfMonth, dow).toDateTime();
            }
            return nextRepeatMonthly(returnDate);
        }
    default:
        throw new IllegalStateException("Schedule has an unknown type: " + schedule.getScheduleType());
    }
}

From source file:com.google.android.apps.paco.NonESMSignalGenerator.java

License:Open Source License

private DateTime nextRepeatMonthly(DateTime midnightTomorrow) {
    if (schedule.getRepeatRate() == 1) {
        return midnightTomorrow;
    }//  w  w  w .  jav  a2 s .co  m
    if (schedule.getByDayOfMonth()) {
        int distanceBetweenStartAndTomorrow = Months
                .monthsBetween(new DateTime(schedule.getBeginDate()).toDateMidnight(), midnightTomorrow)
                .getMonths();
        if (distanceBetweenStartAndTomorrow == 0
                || distanceBetweenStartAndTomorrow == schedule.getRepeatRate()) {
            if ((distanceBetweenStartAndTomorrow == 0 && midnightTomorrow
                    .getDayOfMonth() <= new DateMidnight(schedule.getBeginDate()).getDayOfMonth())) {
                // we crossed a month boundary, so add one month.
                return midnightTomorrow.plusMonths(schedule.getRepeatRate() - 1);
            }
            return midnightTomorrow;
        } else if (distanceBetweenStartAndTomorrow > schedule.getRepeatRate()) {
            int remainder = distanceBetweenStartAndTomorrow % schedule.getRepeatRate();
            return midnightTomorrow.plusMonths(schedule.getRepeatRate() - remainder);
        } else {
            return midnightTomorrow.plusMonths(schedule.getRepeatRate() - distanceBetweenStartAndTomorrow);
        }
    } else {
        int distanceBetweenStartAndTomorrow = Months
                .monthsBetween(new DateTime(schedule.getBeginDate()).toDateMidnight(), midnightTomorrow)
                .getMonths();
        if (distanceBetweenStartAndTomorrow == 0
                || distanceBetweenStartAndTomorrow == schedule.getRepeatRate()) {
            if ((distanceBetweenStartAndTomorrow == 0 && midnightTomorrow
                    .getDayOfMonth() <= new DateMidnight(schedule.getBeginDate()).getDayOfMonth())) {
                // we crossed a month boundary, so add one month.
                return getNthDOWOfMonth(midnightTomorrow.plusMonths(schedule.getRepeatRate() - 1),
                        schedule.getNthOfMonth(), getDOWFromIndexedValue());
            }
            return midnightTomorrow;
        } else if (distanceBetweenStartAndTomorrow > schedule.getRepeatRate()) {
            int remainder = distanceBetweenStartAndTomorrow % schedule.getRepeatRate();
            return getNthDOWOfMonth(midnightTomorrow.plusMonths(schedule.getRepeatRate() - remainder),
                    schedule.getNthOfMonth(), getDOWFromIndexedValue());
        } else {
            return getNthDOWOfMonth(
                    midnightTomorrow.plusMonths(schedule.getRepeatRate() - distanceBetweenStartAndTomorrow),
                    schedule.getNthOfMonth(), getDOWFromIndexedValue());
        }
    }
}