Example usage for org.joda.time Duration toString

List of usage examples for org.joda.time Duration toString

Introduction

In this page you can find the example usage for org.joda.time Duration toString.

Prototype

@ToString
public String toString() 

Source Link

Document

Gets the value as a String in the ISO8601 duration format including only seconds and milliseconds.

Usage

From source file:com.anrisoftware.globalpom.format.duration.DurationFormat.java

License:Open Source License

private void formatDuration(StringBuffer buff, Duration duration) {
    buff.append(duration.toString());
}

From source file:com.anrisoftware.sscontrol.httpd.nginx.nginx.linux.SimpleDurationRenderer.java

License:Open Source License

@Override
public String toString(Object o, String formatString, Locale locale) {
    Duration duration = (Duration) o;
    if (StringUtils.equals(formatString, SIMPLE_ROUND_KEY)) {
        return DurationSimpleFormat.roundSizeUnit(duration.getMillis());
    }/*from  w  w  w  . j  a  v  a 2s .  com*/
    if (startsWith(formatString, SIMPLE_KEY)) {
        return toStringSimple(formatString, duration);
    } else {
        return duration.toString();
    }
}

From source file:com.avid.central.obsplugin.inewslibrary.OBSRundown.java

public String GetEndTime() {
    Duration dur = new Duration(RundownEndTime);
    return dur.toString();
}

From source file:com.avid.central.obsplugin.inewslibrary.OBSRundown.java

public String GetStartTime() {
    Duration dur = new Duration(RundownStartTime);
    return dur.toString();
}

From source file:com.fatboyindustrial.gsonjodatime.DurationConverter.java

License:Open Source License

/**
 * Gson invokes this call-back method during serialization when it encounters a field of the
 * specified type.//from   w ww .j av a  2 s  . co  m
 * <p>
 * In the implementation of this call-back method, you should consider invoking
 * {@link com.google.gson.JsonSerializationContext#serialize(Object, java.lang.reflect.Type)} method to create JsonElements for any
 * non-trivial field of the {@code src} object. However, you should never invoke it on the
 * {@code src} object itself since that will cause an infinite loop (Gson will call your
 * call-back method again).
 * @param src the object that needs to be converted to Json.
 * @param typeOfSrc the actual type (fully genericized version) of the source object.
 * @return a JsonElement corresponding to the specified object.
 */
@Override
public JsonElement serialize(Duration src, Type typeOfSrc, JsonSerializationContext context) {
    return new JsonPrimitive(src.toString());
}

From source file:com.google.errorprone.bugpatterns.testdata.ObjectToStringNegativeCases.java

License:Apache License

public void overridePresentInAbstractClassInHierarchy(Duration durationArg) {
    String unusedString = Duration.standardSeconds(86400).toString();
    System.out.println("test joda string " + Duration.standardSeconds(86400));

    unusedString = durationArg.toString();
    System.out.println("test joda string " + durationArg);
}

From source file:com.kopysoft.chronos.views.ClockFragments.Today.DatePairView.java

License:Open Source License

private void createUI(TodayAdapterPair adpter, Job thisJob) {

    //if(enableLog) Log.d(TAG, "Position: " + position);
    setOrientation(LinearLayout.VERTICAL);

    //retView.setOnItemLongClickListener(LongClickListener);

    header = View.inflate(getContext(), R.layout.today_view, null);

    DateTimeFormatter fmt = DateTimeFormat.forPattern("E, MMM d, yyyy");
    ((TextView) header.findViewById(R.id.date)).setText(fmt.print(gDate));

    if (!showPay()) {
        header.findViewById(R.id.moneyViewText).setVisibility(View.GONE);
        header.findViewById(R.id.moneyViewTotal).setVisibility(View.GONE);
    }/*from  w  w  w  .  j  a v  a  2 s.  c  o m*/

    ListView retView = (ListView) header.findViewById(R.id.listView);
    retView.setOnItemClickListener(listener);

    TextView tx = (TextView) header.findViewById(R.id.timeViewTotal);
    Duration dur = adapter.getTime(true);

    if (dur.getMillis() < 0 && gDate.toDateMidnight().isEqual(new DateMidnight())) {
        dur = dur.plus(DateTime.now().getMillis());
    }

    int seconds = (int) dur.getStandardSeconds();
    int minutes = (seconds / 60) % 60;
    int hours = (seconds / 60 / 60);
    String output = String.format("%d:%02d:%02d", hours, minutes, seconds % 60);

    if (dur.getMillis() >= 0)
        tx.setText(output);
    else
        tx.setText("--:--:--");

    if (enableLog)
        Log.d(TAG, "job: " + thisJob);
    if (enableLog)
        Log.d(TAG, "seconds: " + seconds);
    if (enableLog)
        Log.d(TAG, "dur: " + dur.toString());
    if (enableLog)
        Log.d(TAG, "pay rate: " + thisJob.getPayRate());

    double money = adapter.getPayableTime(gDate.toDateMidnight().isEqual(new DateMidnight()));

    Currency moneyCurrency = Currency.getInstance(Locale.getDefault());
    output = String.format("%s %.2f", moneyCurrency.getSymbol(), money);
    tx = (TextView) header.findViewById(R.id.moneyViewTotal);
    tx.setText(output);
    if (enableLog)
        Log.d(TAG, "pay amount: " + output);

    //header to the row
    addView(header);

    retView.setAdapter(adpter);
    retView.setSelection(0);

    //show button
    if (!gDate.toDateMidnight().isEqual(new DateMidnight())) {
        header.findViewById(R.id.clockInAndOutButton).setVisibility(View.GONE);
    } else {
        (header.findViewById(R.id.clockInAndOutButton)).setOnClickListener(buttonListener);
        if (dur.getMillis() < 0) {
            ((Button) header.findViewById(R.id.clockInAndOutButton)).setText("Clock Out");
        } else {
            ((Button) header.findViewById(R.id.clockInAndOutButton)).setText("Clock In");
        }
    }

}

From source file:de.arkraft.jenkins.JenkinsHelper.java

License:Apache License

public static GsonBuilder getGsonBuilder() {
    GsonBuilder builder = new GsonBuilder();

    builder.registerTypeAdapter(DateTime.class, new JsonDeserializer<DateTime>() {
        @Override//www  .  j a  va2s .c  o  m
        public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                throws JsonParseException {
            // using the correct parser right away should save init time compared to new DateTime(<string>)
            return ISO_8601_WITH_MILLIS.parseDateTime(json.getAsString());
        }
    });

    builder.registerTypeAdapter(DateTime.class, new JsonSerializer<DateTime>() {
        @Override
        public JsonElement serialize(DateTime src, Type typeOfSrc, JsonSerializationContext context) {
            return new JsonPrimitive(src.toString());
        }
    });

    builder.registerTypeAdapter(Duration.class, new JsonDeserializer() {
        @Override
        public Object deserialize(JsonElement json, Type type,
                JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
            return Duration.parse("PT" + json.getAsString() + "S");
        }
    });

    builder.registerTypeAdapter(Action.class, new JsonDeserializer<Action>() {
        @Override
        public Action deserialize(JsonElement jsonElement, Type type,
                JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {

            JsonObject object = ((JsonObject) jsonElement);
            if (object.has("causes")) {
                JsonElement element = object.get("causes");
                if (element.isJsonArray()) {
                    return jsonDeserializationContext.deserialize(element, Causes.class);
                }
            }
            if (object.has("failCount")) {
                return jsonDeserializationContext.deserialize(object, CountAction.class);
            }
            return null;
        }
    });

    builder.registerTypeAdapter(ChangeSet.class, new JsonDeserializer<ChangeSet>() {
        @Override
        public ChangeSet deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
                throws JsonParseException {
            ChangeSet changeSet = new ChangeSet();
            JsonObject object = (JsonObject) jsonElement;
            if (object.has("items") && object.get("items").isJsonArray()) {
                for (JsonElement element : object.get("items").getAsJsonArray()) {
                    ChangeSet.Change change = context.deserialize(element, ChangeSet.Change.class);
                    changeSet.add(change);
                }
            }
            if (object.has("kind")) {
                changeSet.setKind(object.get("kind").getAsString());
            }
            return changeSet;
        }
    });

    builder.registerTypeAdapter(Duration.class, new JsonSerializer<Duration>() {
        @Override
        public JsonElement serialize(Duration duration, Type type,
                JsonSerializationContext jsonSerializationContext) {
            return new JsonPrimitive(duration.toString().replace("PT", "").replace("S", ""));
        }
    });

    builder.registerTypeAdapter(EditType.class, new JsonDeserializer<EditType>() {
        @Override
        public EditType deserialize(JsonElement jsonElement, Type type,
                JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
            return EditType.byName(jsonElement.getAsString());
        }
    });

    builder.registerTypeAdapter(HealthIcon.class, new JsonDeserializer<HealthIcon>() {
        @Override
        public HealthIcon deserialize(JsonElement jsonElement, Type type,
                JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
            return HealthIcon.fromName(jsonElement.toString());
        }
    });

    builder.registerTypeAdapter(Queue.class, new JsonDeserializer<Queue>() {
        @Override
        public Queue deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
                throws JsonParseException {
            Queue queue = new Queue();
            JsonObject jsonObject = (JsonObject) jsonElement;
            if (jsonObject.has("items") && jsonObject.get("items").isJsonArray()) {
                for (JsonElement element : jsonObject.get("items").getAsJsonArray()) {
                    Queue.Item build = context.deserialize(element, Queue.Item.class);
                    queue.add(build);
                }
            }
            return queue;
        }
    });

    builder.registerTypeAdapter(JobCollection.class, new JsonDeserializer<JobCollection>() {
        @Override
        public JobCollection deserialize(JsonElement json, Type type, JsonDeserializationContext context)
                throws JsonParseException {
            JobCollection jobs = new JobCollection();
            JsonObject object = (JsonObject) json;
            if (object.has("jobs") && object.get("jobs").isJsonArray()) {
                for (JsonElement element : object.get("jobs").getAsJsonArray()) {
                    Job job = context.deserialize(element, Job.class);
                    jobs.add(job);
                }
            }
            return jobs;
        }
    });

    builder.registerTypeAdapter(BallColor.class, new JsonDeserializer<BallColor>() {
        @Override
        public BallColor deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext json)
                throws JsonParseException {
            return BallColor.valueOf(jsonElement.getAsString().toUpperCase());
        }
    });

    return builder;
}

From source file:es.usc.citius.servando.calendula.pinlock.UnlockStateManager.java

License:Open Source License

/**
 * Checks if unlock is set and not expired
 *
 * @return <code>true</code> if unlocked, false otherwise.
 *//*from w ww .j a  va  2s.  c  o  m*/
public boolean isUnlocked() {
    LogUtil.v(TAG, "isUnlocked() called");
    if (unlockTimestamp != null) {
        Duration diff = new Duration(unlockTimestamp, DateTime.now());
        // need to be a string to use a ListPreference
        final String maxDurationStr = PreferenceUtils.getString(PreferenceKeys.UNLOCK_PIN_TIMEOUT,
                DEFAULT_UNLOCK_DURATION_SECONDS);
        Duration maxDuration = Duration.standardSeconds(Integer.parseInt(maxDurationStr));
        LogUtil.d(TAG, "Max unlock duration is " + maxDuration.toString());
        if (diff.compareTo(maxDuration) <= 0) {
            LogUtil.d(TAG, "isUnlocked() returned: " + true);
            return true;
        } else {
            LogUtil.d(TAG, "isUnlocked: unlock has expired, unsetting and returning null");
            unlockTimestamp = null;
            return false;
        }
    } else {
        LogUtil.d(TAG, "isUnlocked: timestamp is null");
    }
    return false;
}

From source file:google.registry.model.translators.DurationTranslatorFactory.java

License:Open Source License

@Override
protected SimpleTranslator<Duration, String> createTranslator() {
    return new SimpleTranslator<Duration, String>() {
        @Override/*from   w ww. j av a 2s.c  o m*/
        public Duration loadValue(String datastoreValue) {
            return Duration.parse(datastoreValue);
        }

        @Override
        public String saveValue(Duration pojoValue) {
            return pojoValue.toString();
        }
    };
}