Java 类org.joda.time.MutableDateTime 实例源码

项目:Android_watch_magpie    文件:GcmMessageHandler.java   
private void processAlertNotification(Bundle data) {

        String pubUsername = data.getString(PUBLISHER_USERNAME);
        String type = data.getString(ALERT_TYPE).toLowerCase();

        long timestamp = Long.parseLong(data.getString(ALERT_TIMESTAMP));
        MutableDateTime date = new MutableDateTime(timestamp);
        DateTimeFormatter dtf = DateTimeFormat.forPattern("kk:mm dd/MM/yyyy");

        int notificationId = 2;

        String msg =  "Alert from " + pubUsername + "\nType: " + type + "\nDate: " + date.toString(dtf);

        Notification.Builder notificationBuilder = new Notification.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("MAGPIE Notification")
                .setContentText("Alert from " + pubUsername)
                .setStyle(new Notification.BigTextStyle().bigText(msg));

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(notificationId, notificationBuilder.build());

    }
项目:elasticsearch_my    文件:SimpleJodaTests.java   
public void testRoundingWithTimeZone() {
    MutableDateTime time = new MutableDateTime(DateTimeZone.UTC);
    time.setZone(DateTimeZone.forOffsetHours(-2));
    time.setRounding(time.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);

    MutableDateTime utcTime = new MutableDateTime(DateTimeZone.UTC);
    utcTime.setRounding(utcTime.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);

    time.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));
    utcTime.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));

    assertThat(time.toString(), equalTo("2009-02-02T00:00:00.000-02:00"));
    assertThat(utcTime.toString(), equalTo("2009-02-03T00:00:00.000Z"));
    // the time is on the 2nd, and utcTime is on the 3rd, but, because time already encapsulates
    // time zone, the millis diff is not 24, but 22 hours
    assertThat(time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));

    time.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
    utcTime.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
    assertThat(time.toString(), equalTo("2009-02-03T00:00:00.000-02:00"));
    assertThat(utcTime.toString(), equalTo("2009-02-04T00:00:00.000Z"));
    assertThat(time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));
}
项目:jcron    文件:SingleParser.java   
@Override
public Set<Integer> parse(DateTime dateTime) {
    if (getType().equals(DurationField.DAY_OF_WEEK)) {
        if (set != null) {
            Set<Integer> result = new HashSet<>();

            MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
            int maxDayOfMonth = mdt.getDayOfMonth();
            for (int i = 1; i <= maxDayOfMonth; i++) {
                mdt.setDayOfMonth(i);
                if (set.contains((mdt.getDayOfWeek() + 1) % 7)) {
                    result.add(mdt.getDayOfMonth());
                }
            }

            return result;
        }
    }

    return set;
}
项目:jcron    文件:StepParser.java   
@Override
public Set<Integer> parse(DateTime dateTime) {
    if (getType() == DurationField.DAY_OF_WEEK) {
        if (set != null) {
            Set<Integer> result = new HashSet<>();

            MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
            int maxDayOfMonth = mdt.getDayOfMonth();
            for (int i = 1; i <= maxDayOfMonth; i++) {
                mdt.setDayOfMonth(i);
                if (set.contains((mdt.getDayOfWeek() + 1) % 7)) {
                    result.add(mdt.getDayOfMonth());
                }
            }

            return result;
        }
    }

    return set;
}
项目:jcron    文件:AsteriskParser.java   
@Override
public Set<Integer> parse(DateTime dateTime) {
    Set<Integer> set = new HashSet<>();
    if (getType().equals(DurationField.DAY_OF_MONTH)) {
        MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
        int maxDayOfMonth = mdt.getDayOfMonth();
        for (int i = 1; i <= maxDayOfMonth; i++) {
            set.add(i);
        }
    } else {
        int start = getRange().lowerEndpoint();
        int end = getRange().upperEndpoint();
        for (int i = start; i < end + 1; i++) {
            set.add(i);
        }
    }

    return set;
}
项目:jcron    文件:RangeParser.java   
@Override
public Set<Integer> parse(DateTime dateTime) {
    if (getType().equals(DurationField.DAY_OF_WEEK)) {
        if (set != null) {
            Set<Integer> result = new HashSet<>();
            MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
            int maxDayOfMonth = mdt.getDayOfMonth();
            for (int i = 1; i <= maxDayOfMonth; i++) {
                mdt.setDayOfMonth(i);
                if (set.contains((mdt.getDayOfWeek() + 1) % 7)) {
                    result.add(mdt.getDayOfMonth());
                }
            }

            return result;
        }
    }

    return set;
}
项目:jcron    文件:CronExpression.java   
public List<DateTime> getTimeAfter(DateTime dateTime, int n) throws ParseException {
    if (n < 1) {
        throw new IllegalArgumentException("n should be > 0, but given " + n);
    }

    List<DateTime> list = null;
    MutableDateTime mdt = dateTime.toMutableDateTime();
    for (int i = 0; i < n; i++) {
        DateTime value = getTimeAfter(mdt.toDateTime());
        if (value != null) {
            if (list == null) {
                list = new ArrayList<>();
            }
            list.add(value);
            mdt.setMillis(value.getMillis());
        } else {
            break;
        }
    }

    return list;
}
项目:jcron    文件:CronExpression.java   
public List<DateTime> getTimeBefore(DateTime dateTime, int n) throws ParseException {
    if (n < 1) {
        throw new IllegalArgumentException("n should be > 0, but given " + n);
    }

    List<DateTime> list = null;
    MutableDateTime mdt = dateTime.toMutableDateTime();
    for (int i = 0; i < n; i++) {
        DateTime value = getTimeBefore(mdt.toDateTime());
        if (value != null) {
            if (list == null) {
                list = new ArrayList<>();
            }
            list.add(value);
            mdt.setMillis(value.getMillis());
        } else {
            break;
        }
    }

    return list;
}
项目:jcron    文件:WeekAbbreviationParser.java   
@Override
public Set<Integer> parse(DateTime dateTime) {
    Set<Integer> result = new HashSet<>();
    if (index != -1) {
        MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
        int maxDayOfMonth = mdt.getDayOfMonth();
        for (int i = 1; i <= maxDayOfMonth; i++) {
            mdt.setDayOfMonth(i);
            if (index == mdt.getDayOfWeek()) {
                result.add(mdt.getDayOfMonth());
            }
        }
    }

    return result;
}
项目:fili    文件:SqlTimeConverter.java   
/**
 * Given an array of strings (a row from a {@link java.sql.ResultSet}) and the
 * {@link Granularity} used to make groupBy statements on time, it will parse out a {@link DateTime}
 * for the row which represents the beginning of the interval it was grouped on.
 *
 * @param offset the last column before the date fields.
 * @param recordValues  The results returned by Sql needed to read the time columns.
 * @param druidQuery  The original druid query which was made using calling
 * {@link #buildGroupBy(RelBuilder, Granularity, String)}.
 *
 * @return the datetime for the start of the interval.
 */
public DateTime getIntervalStart(int offset, String[] recordValues, DruidAggregationQuery<?> druidQuery) {
    List<SqlDatePartFunction> times = timeGrainToDatePartFunctions(druidQuery.getGranularity());

    DateTimeZone timeZone = getTimeZone(druidQuery);

    if (times.isEmpty()) {
        throw new UnsupportedOperationException("Can't parse dateTime for if no times were grouped on.");
    }

    MutableDateTime mutableDateTime = new MutableDateTime(0, 1, 1, 0, 0, 0, 0, timeZone);

    for (int i = 0; i < times.size(); i++) {
        int value = Integer.parseInt(recordValues[offset + i]);
        SqlDatePartFunction fn = times.get(i);
        setDateTime(value, fn, mutableDateTime);
    }

    return mutableDateTime.toDateTime();
}
项目:fili    文件:SqlTimeConverter.java   
/**
 * Sets the correct part of a {@link DateTime} corresponding to a
 * {@link SqlDatePartFunction}.
 *
 * @param value  The value to be set for the dateTime with the sqlDatePartFn
 * @param sqlDatePartFn  The function used to extract part of a date with sql.
 * @param dateTime  The original dateTime to create a copy of.
 */
protected void setDateTime(int value, SqlDatePartFunction sqlDatePartFn, MutableDateTime dateTime) {
    if (YEAR.equals(sqlDatePartFn)) {
        dateTime.setYear(value);
    } else if (MONTH.equals(sqlDatePartFn)) {
        dateTime.setMonthOfYear(value);
    } else if (WEEK.equals(sqlDatePartFn)) {
        dateTime.setWeekOfWeekyear(value);
        dateTime.setDayOfWeek(1);
    } else if (DAYOFYEAR.equals(sqlDatePartFn)) {
        dateTime.setDayOfYear(value);
    } else if (HOUR.equals(sqlDatePartFn)) {
        dateTime.setHourOfDay(value);
    } else if (MINUTE.equals(sqlDatePartFn)) {
        dateTime.setMinuteOfHour(value);
    } else if (SECOND.equals(sqlDatePartFn)) {
        dateTime.setSecondOfMinute(value);
    } else {
        throw new IllegalArgumentException("Can't set value " + value + " for " + sqlDatePartFn);
    }
}
项目:kc-rice    文件:DocumentSearchInternalUtils.java   
public static DateTime getLowerDateTimeBound(String dateRange) throws ParseException {
    Range range = SearchExpressionUtils.parseRange(dateRange);
    if (range == null) {
        throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange);
    }
    if (range.getLowerBoundValue() != null) {
        java.util.Date lowerRangeDate = null;
        try{
            lowerRangeDate = CoreApiServiceLocator.getDateTimeService().convertToDate(range.getLowerBoundValue());
        }catch(ParseException pe){
            GlobalVariables.getMessageMap().putError("dateFrom", RiceKeyConstants.ERROR_CUSTOM, pe.getMessage());
        }
        MutableDateTime dateTime = new MutableDateTime(lowerRangeDate);
        dateTime.setMillisOfDay(0);
        return dateTime.toDateTime();
    }
    return null;
}
项目:kc-rice    文件:DocumentSearchInternalUtils.java   
public static DateTime getUpperDateTimeBound(String dateRange) throws ParseException {
    Range range = SearchExpressionUtils.parseRange(dateRange);
    if (range == null) {
        throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange);
    }
    if (range.getUpperBoundValue() != null) {
        java.util.Date upperRangeDate = null;
        try{
            upperRangeDate = CoreApiServiceLocator.getDateTimeService().convertToDate(range.getUpperBoundValue());
        }catch(ParseException pe){
            GlobalVariables.getMessageMap().putError("dateCreated", RiceKeyConstants.ERROR_CUSTOM, pe.getMessage());
        }
        MutableDateTime dateTime = new MutableDateTime(upperRangeDate);
        // set it to the last millisecond of the day
        dateTime.setMillisOfDay((24 * 60 * 60 * 1000) - 1);
        return dateTime.toDateTime();
    }
    return null;
}
项目:sql-layer    文件:MYearWeek.java   
@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output)
{
    int date = inputs.get(0).getInt32();
    long ymd[] = MDateAndTime.decodeDate(date);
    int mode = getMode(context, inputs);
    if (!MDateAndTime.isValidDateTime(ymd, ZeroFlag.YEAR) || mode < 0)
    {
        context.warnClient(new InvalidDateFormatException("Invalid DATE value " , date + ""));
        output.putNull();
    }
    else
    {
        output.putInt32(modes[(int) mode].getYearWeek(new MutableDateTime(DateTimeZone.forID(context.getCurrentTimezone())),
                                                      (int)ymd[0], (int)ymd[1], (int)ymd[2]));
    }
}
项目:https-github.com-h2oai-h2o-3    文件:ASTTime.java   
@Override Val apply( Env env, Env.StackHelp stk, AST asts[] ) {
  Val val = asts[1].exec(env);
  switch( val.type() ) {
  case Val.NUM: 
    double d = val.getNum();
    return new ValNum(Double.isNaN(d) ? d : op(new MutableDateTime(0),d));
  case Val.FRM: 
    Frame fr = stk.track(val).getFrame();
    if( fr.numCols() > 1 ) throw water.H2O.unimpl();
    return new ValFrame(new MRTask() {
        @Override public void map( Chunk chk, NewChunk cres ) {
          MutableDateTime mdt = new MutableDateTime(0,ParseTime.getTimezone());
          for( int i=0; i<chk._len; i++ )
            cres.addNum(chk.isNA(i) ? Double.NaN : op(mdt,chk.at8(i)));
        }
      }.doAll_numericResult(1,fr).outputFrame(fr._names, factors()));
  default: throw water.H2O.fail();
  }
}
项目:sql-layer    文件:MYearWeek.java   
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);
    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int dayOfYear = cal.getDayOfYear();

    if (dayOfYear < firstD) return modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
    else return yr * 100 + (dayOfYear - firstD) / 7 +1;
}
项目:sql-layer    文件:MDateAddSub.java   
@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output)
{
    ValueSource arg0 = inputs.get(pos0);
    long ymd[] = firstArg.decode(arg0, context);
    if (ymd == null)
    {
        output.putNull();
        context.warnClient(new InvalidDateFormatException("DATE", arg0.toString()));
    }
    else
    {
        MutableDateTime dt = MDateAndTime.toJodaDateTime(ymd, "UTC");    // calculations should be done
        helper.compute(dt, secondArg.toMillis(inputs.get(pos1)));      // in UTC (to avoid daylight-saving side effects)
        firstArg.adjustFirstArg(inputs.get(pos1).getType()).putResult(output, dt, context);
    }
}
项目:sql-layer    文件:MWeek.java   
@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output)
{
    int date = inputs.get(0).getInt32();
    long ymd[] = MDateAndTime.decodeDate(date);
    int mode = getMode(context, inputs);
    if (!MDateAndTime.isValidDateTime(ymd, ZeroFlag.YEAR) || mode < 0)
    {
        context.warnClient(new InvalidDateFormatException("date", Integer.toString(date)));
        output.putNull();
    }
    else
    {
        output.putInt32(modes[(int) mode].getWeek(new MutableDateTime(DateTimeZone.forID(context.getCurrentTimezone())),
                                              (int)ymd[0], (int)ymd[1], (int)ymd[2]));
    }
}
项目:philadelphia    文件:FIXValue.java   
/**
 * Get the value as a timestamp.
 *
 * @param t a timestamp
 * @throws FIXValueFormatException if the value is not a timestamp
 */
public void asTimestamp(MutableDateTime t) {
    if (length != 17 && length != 21)
        throw new FIXValueFormatException("Not a timestamp");

    int year           = getDigits(4, offset + 0);
    int monthOfYear    = getDigits(2, offset + 4);
    int dayOfMonth     = getDigits(2, offset + 6);
    int hourOfDay      = getDigits(2, offset + 9);
    int minuteOfHour   = getDigits(2, offset + 12);
    int secondOfMinute = getDigits(2, offset + 15);
    int millisOfSecond = length == 21 ? getDigits(3, offset + 18) : 0;

    t.setDateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour,
            secondOfMinute, millisOfSecond);
}
项目:philadelphia    文件:FIXMessageTest.java   
@Test
public void format() {
    MutableDateTime timestamp = new MutableDateTime(2015, 9, 24, 9, 30, 5, 250);

    message.addField(ClOrdID).setString("123");
    message.addField(HandlInst).setChar(HandlInstValues.AutomatedExecutionNoIntervention);
    message.addField(Symbol).setString("FOO");
    message.addField(Side).setChar(SideValues.Buy);
    message.addField(TransactTime).setTimestamp(timestamp, true);
    message.addField(OrderQty).setInt(100);
    message.addField(OrdType).setChar(OrdTypeValues.Limit);
    message.addField(Price).setFloat(150.25, 2);

    ByteBuffer buffer = ByteBuffer.allocateDirect(256);

    message.put(buffer);
    buffer.flip();

    assertEquals("11=123\u000121=1\u000155=FOO\u000154=1\u0001" +
            "60=20150924-09:30:05.250\u000138=100\u000140=2\u0001" +
            "44=150.25\u0001", ByteBuffers.getString(buffer));
}
项目:philadelphia    文件:FIXMessageTest.java   
@Test
public void print() {
    MutableDateTime timestamp = new MutableDateTime(2015, 9, 24, 9, 30, 5, 250);

    message.addField(ClOrdID).setString("123");
    message.addField(HandlInst).setChar(HandlInstValues.AutomatedExecutionNoIntervention);
    message.addField(Symbol).setString("FOO");
    message.addField(Side).setChar(SideValues.Buy);
    message.addField(TransactTime).setTimestamp(timestamp, true);
    message.addField(OrderQty).setInt(100);
    message.addField(OrdType).setChar(OrdTypeValues.Limit);
    message.addField(Price).setFloat(150.25, 2);

    assertEquals("11=123|21=1|55=FOO|54=1|60=20150924-09:30:05.250|" +
            "38=100|40=2|44=150.25|", message.toString());
}
项目:TinyTravelTracker    文件:ZoneInfoCompiler.java   
static int parseTime(String str) {
    DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction();
    MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology());
    int pos = 0;
    if (str.startsWith("-")) {
        pos = 1;
    }
    int newPos = p.parseInto(mdt, str, pos);
    if (newPos == ~pos) {
        throw new IllegalArgumentException(str);
    }
    int millis = (int)mdt.getMillis();
    if (pos == 1) {
        millis = -millis;
    }
    return millis;
}
项目:invesdwin-util    文件:FDate.java   
public FDate add(final FTimeUnit field, final int amount) {
    final MutableDateTime delegate = newMutableDateTime();
    final int usedAmount;
    final DurationFieldType usedField;
    switch (field) {
    case MILLENIA:
        usedField = FTimeUnit.YEARS.jodaTimeValue();
        usedAmount = amount * FTimeUnit.YEARS_IN_MILLENIUM;
        break;
    case CENTURIES:
        usedField = FTimeUnit.YEARS.jodaTimeValue();
        usedAmount = amount * FTimeUnit.YEARS_IN_CENTURY;
        break;
    case DECADES:
        usedField = FTimeUnit.YEARS.jodaTimeValue();
        usedAmount = amount * FTimeUnit.YEARS_IN_DECADE;
        break;
    default:
        usedField = field.jodaTimeValue();
        usedAmount = amount;
        break;
    }
    delegate.add(usedField, usedAmount);
    return new FDate(delegate);
}
项目:jcron    文件:SingleParser.java   
@Override
public Set<Integer> parse(DateTime dateTime) {
    if (getType().equals(DurationField.DAY_OF_WEEK)) {
        if (set != null) {
            Set<Integer> result = new HashSet<>();

            MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
            int maxDayOfMonth = mdt.getDayOfMonth();
            for (int i = 1; i <= maxDayOfMonth; i++) {
                mdt.setDayOfMonth(i);
                if (set.contains((mdt.getDayOfWeek() + 1) % 7)) {
                    result.add(mdt.getDayOfMonth());
                }
            }

            return result;
        }
    }

    return set;
}
项目:jcron    文件:StepParser.java   
@Override
public Set<Integer> parse(DateTime dateTime) {
    if (getType() == DurationField.DAY_OF_WEEK) {
        if (set != null) {
            Set<Integer> result = new HashSet<>();

            MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
            int maxDayOfMonth = mdt.getDayOfMonth();
            for (int i = 1; i <= maxDayOfMonth; i++) {
                mdt.setDayOfMonth(i);
                if (set.contains((mdt.getDayOfWeek() + 1) % 7)) {
                    result.add(mdt.getDayOfMonth());
                }
            }

            return result;
        }
    }

    return set;
}
项目:jcron    文件:AsteriskParser.java   
@Override
public Set<Integer> parse(DateTime dateTime) {
    Set<Integer> set = new HashSet<>();
    if (getType().equals(DurationField.DAY_OF_MONTH)) {
        MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
        int maxDayOfMonth = mdt.getDayOfMonth();
        for (int i = 1; i <= maxDayOfMonth; i++) {
            set.add(i);
        }
    } else {
        int start = getRange().lowerEndpoint();
        int end = getRange().upperEndpoint();
        for (int i = start; i < end + 1; i++) {
            set.add(i);
        }
    }

    return set;
}
项目:jcron    文件:RangeParser.java   
@Override
public Set<Integer> parse(DateTime dateTime) {
    if (getType().equals(DurationField.DAY_OF_WEEK)) {
        if (set != null) {
            Set<Integer> result = new HashSet<>();
            MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
            int maxDayOfMonth = mdt.getDayOfMonth();
            for (int i = 1; i <= maxDayOfMonth; i++) {
                mdt.setDayOfMonth(i);
                if (set.contains((mdt.getDayOfWeek() + 1) % 7)) {
                    result.add(mdt.getDayOfMonth());
                }
            }

            return result;
        }
    }

    return set;
}
项目:jcron    文件:CronExpression.java   
public List<DateTime> getTimeAfter(DateTime dateTime, int n) throws ParseException {
    if (n < 1) {
        throw new IllegalArgumentException("n should be > 0, but given " + n);
    }

    List<DateTime> list = null;
    MutableDateTime mdt = dateTime.toMutableDateTime();
    for (int i = 0; i < n; i++) {
        DateTime value = getTimeAfter(mdt.toDateTime());
        if (value != null) {
            if (list == null) {
                list = new ArrayList<>();
            }
            list.add(value);
            mdt.setMillis(value.getMillis());
        } else {
            break;
        }
    }

    return list;
}
项目:components    文件:XMLGregorianCalendarToDateTimeConverter.java   
@Override
public Object convertToAvro(XMLGregorianCalendar xts) {
    if (xts == null) {
        return null;
    }

    MutableDateTime dateTime = new MutableDateTime();
    try {
        dateTime.setYear(xts.getYear());
        dateTime.setMonthOfYear(xts.getMonth());
        dateTime.setDayOfMonth(xts.getDay());
        dateTime.setHourOfDay(xts.getHour());
        dateTime.setMinuteOfHour(xts.getMinute());
        dateTime.setSecondOfMinute(xts.getSecond());
        dateTime.setMillisOfSecond(xts.getMillisecond());

        DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000);
        if (tz != null) {
            dateTime.setZoneRetainFields(tz);
        }

        return Long.valueOf(dateTime.getMillis());
    } catch (IllegalArgumentException e) {
        throw new ComponentException(e);
    }
}
项目:misfit-analyser    文件:DailyActivity.java   
public DateTime getDateTimeBegin() {
    if (mDateTimeBegin == null) {
        MutableDateTime begin = new MutableDateTime(getDate());
        int hour = 0;
        boolean excepted = true;
        while (excepted) {
            try {
                begin.setHourOfDay(hour);
                begin.setMinuteOfHour(0);
                begin.setSecondOfMinute(0);
                begin.setMillisOfSecond(0);
                hour++;
                excepted = false;
            } catch (Exception e) {

            }
        }
        mDateTimeBegin = begin.toDateTime();
    }
    return mDateTimeBegin;
}
项目:misfit-analyser    文件:DailyActivity.java   
public DateTime getDateTimeEnd() {
    if (mDateTimeEnd == null) {
        MutableDateTime end = new MutableDateTime(getDate());
        int hour = 23;
        boolean excepted = true;
        while (excepted) {
            try {
                end.setHourOfDay(hour);
                end.setMinuteOfHour(59);
                end.setSecondOfMinute(59);
                end.setMillisOfSecond(999);
                hour--;
                excepted = false;
            } catch (Exception e) {

            }
        }
        mDateTimeEnd = end.toDateTime();
    }
    return mDateTimeEnd;
}
项目:elasticsearch_my    文件:DateObjectValueSource.java   
@Override
@SuppressWarnings("rawtypes") // ValueSource uses a rawtype
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicNumericFieldData leafData = (AtomicNumericFieldData) fieldData.load(leaf);
    MutableDateTime joda = new MutableDateTime(0, DateTimeZone.UTC);
    NumericDoubleValues docValues = multiValueMode.select(leafData.getDoubleValues(), 0d);
    return new DoubleDocValues(this) {
      @Override
      public double doubleVal(int docId) {
        long millis = (long)docValues.get(docId);
        joda.setMillis(millis);
        return function.applyAsInt(joda);
      }
    };
}
项目:elasticsearch_my    文件:ScriptDocValues.java   
/**
 * Refresh the backing array. Package private so it can be called when {@link Longs} loads dates.
 */
void refreshArray() {
    if (values.count() == 0) {
        return;
    }
    if (dates == null) {
        // Happens for the document. We delay allocating dates so we can allocate it with a reasonable size.
        dates = new MutableDateTime[values.count()];
        for (int i = 0; i < dates.length; i++) {
            dates[i] = new MutableDateTime(values.valueAt(i), DateTimeZone.UTC);
        }
        return;
    }
    if (values.count() > dates.length) {
        // Happens when we move to a new document and it has more dates than any documents before it.
        MutableDateTime[] backup = dates;
        dates = new MutableDateTime[values.count()];
        System.arraycopy(backup, 0, dates, 0, backup.length);
        for (int i = 0; i < backup.length; i++) {
            dates[i].setMillis(values.valueAt(i));
        }
        for (int i = backup.length; i < dates.length; i++) {
            dates[i] = new MutableDateTime(values.valueAt(i), DateTimeZone.UTC);
        }
        return;
    }
    for (int i = 0; i < values.count(); i++) {
        dates[i].setMillis(values.valueAt(i));
    }
}
项目:elasticsearch_my    文件:SimpleJodaTests.java   
public void testUpperBound() {
    MutableDateTime dateTime = new MutableDateTime(3000, 12, 31, 23, 59, 59, 999, DateTimeZone.UTC);
    DateTimeFormatter formatter = ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC);

    String value = "2000-01-01";
    int i = formatter.parseInto(dateTime, value, 0);
    assertThat(i, equalTo(value.length()));
    assertThat(dateTime.toString(), equalTo("2000-01-01T23:59:59.999Z"));
}
项目:elasticsearch_my    文件:SimpleJodaTests.java   
public void testRounding() {
    long TIME = utcTimeInMillis("2009-02-03T01:01:01");
    MutableDateTime time = new MutableDateTime(DateTimeZone.UTC);
    time.setMillis(TIME);
    assertThat(time.monthOfYear().roundFloor().toString(), equalTo("2009-02-01T00:00:00.000Z"));
    time.setMillis(TIME);
    assertThat(time.hourOfDay().roundFloor().toString(), equalTo("2009-02-03T01:00:00.000Z"));
    time.setMillis(TIME);
    assertThat(time.dayOfMonth().roundFloor().toString(), equalTo("2009-02-03T00:00:00.000Z"));
}
项目:Android_watch_magpie    文件:MagpieFragment.java   
public PhysioMeasurement(TextView valueTxtView, TextView dateTxtView, TextView timeTxtView, String units) {
    this.valueTxtView = valueTxtView;
    this.timestamp = MutableDateTime.now();
    this.dateTxtView = dateTxtView;
    this.timeTxtView = timeTxtView;
    this.units = units;
}
项目:goobi-viewer-indexer    文件:MetadataHelper.java   
/**
 * 
 * @param value
 * @return
 * @should convert date correctly
 */
static String convertDateStringForSolrField(String value) {
    List<PrimitiveDate> dates = normalizeDate(value, 4);
    if (!dates.isEmpty()) {
        PrimitiveDate date = dates.get(0);
        if (date.getYear() != null) {
            MutableDateTime mdt = new MutableDateTime(date.getYear(), date.getMonth() != null ? date.getMonth() : 1, date.getDay() != null ? date
                    .getDay() : 1, 0, 0, 0, 0);
            return formatterISO8601DateTimeFullWithTimeZone.print(mdt);
        }
    }

    logger.warn("Could not parse date from value: {}", value);
    return null;
}
项目:Red-Calorie    文件:RxTimePicker.java   
@NonNull
@CheckResult
public static Observable<DateTime> openPicker(Context context, DateTime startingTime) {
    boolean is24h = DateFormat.is24HourFormat(context);
    int hour = startingTime.getHourOfDay();
    int minute = startingTime.getMinuteOfHour();
    final AtomicReference<Func1<DateTime, Void>> output = new AtomicReference<>(null);
    final TimePickerDialog timePickerDialog = new TimePickerDialog(context,
            (view, hourOfDay, minute1) -> {
                MutableDateTime outputTime = startingTime.toMutableDateTime();
                outputTime.setMinuteOfDay(minute1);
                outputTime.setHourOfDay(hourOfDay);
                Func1<DateTime, Void> dateTimeCallable = output.get();
                if (dateTimeCallable != null) {
                    dateTimeCallable.call(outputTime.toDateTime());
                }
            },
            hour, minute, is24h);
    timePickerDialog.show();
    return Observable.unsafeCreate(subscriber -> {
        output.set(dateTime -> {
            if (!subscriber.isUnsubscribed()) {
                subscriber.onNext(dateTime);
                subscriber.onCompleted();
            }
            return null;
        });
        subscriber.add(new MainThreadSubscription() {
            @Override
            protected void onUnsubscribe() {
                timePickerDialog.cancel();
            }
        });
    });
}
项目:Udacity-Capstone-Project    文件:DatePickerFragment.java   
public void onDateSet(DatePicker view, int year, int month, int day) {
    // Do something with the date chosen by the user
    mutableDateTimeDate = new MutableDateTime();
    mutableDateTimeDate.setYear(year);
    mutableDateTimeDate.setMonthOfYear(month + 1);
    mutableDateTimeDate.setDayOfMonth(day);
    toShowResult.setText(DateTimeUtils.getStringPatternFromDateTime(toShowResult.getContext().getString(R.string.date_register_formatter), mutableDateTimeDate));
}
项目:Udacity-Capstone-Project    文件:FrgWorkoutResume.java   
private void intViews() {
    rVFrgWorkoutResume.setLayoutManager(new LinearLayoutManager(getActivity()));
    rVFrgWorkoutResume.setAdapter(adapter);
    rVFrgWorkoutResume.setHasFixedSize(true);
    tVFrgWorkoutDate.setVisibility(viewType == FINISH ? View.GONE : View.VISIBLE);
    if (workout != null) {
        tVFrgWorkoutName.setText(workout.getName());
        tVFrgWorkoutRounds.setText(getString(R.string.frg_do_workout_rounds_of_exercises, workout.getCurrentRound(), workout.getRounds()));
        tVFrgWorkoutRestExercise.setText(getString(R.string.frg_workout_rest_between_exercise, workout.getRestBetweenExercise()));
        tVFrgWorkoutRestRounds.setText(getString(R.string.frg_workout_rest_rounds, workout.getRestRoundsExercise()));
        tVFrgWorkoutDate.setText(DateTimeUtils.getStringPatternFromDateTime(
                tVFrgWorkoutDate.getContext().getString(R.string.date_register_formatter),
                new MutableDateTime(workout.getDateCompleted())));
    }
}