List of usage examples for org.joda.time DateTime toDateTime
public DateTime toDateTime(Chronology chronology)
this
if possible. From source file:com.ning.billing.junction.plumbing.billing.BillCycleDayCalculator.java
License:Apache License
@VisibleForTesting int calculateBcdFromSubscription(final Subscription subscription, final Plan plan, final Account account, final Catalog catalog, final InternalCallContext context) throws AccountApiException, CatalogApiException { // Retrieve the initial phase type for that subscription // TODO - this should be extracted somewhere, along with this code above final PhaseType initialPhaseType; final List<EffectiveSubscriptionInternalEvent> transitions = entitlementApi.getAllTransitions(subscription, context);/* w w w .j a v a2s .co m*/ if (transitions.size() == 0) { initialPhaseType = null; } else { final DateTime requestedDate = subscription.getStartDate(); final String initialPhaseString = transitions.get(0).getNextPhase(); if (initialPhaseString == null) { initialPhaseType = null; } else { final PlanPhase initialPhase = catalog.findPhase(initialPhaseString, requestedDate, subscription.getStartDate()); if (initialPhase == null) { initialPhaseType = null; } else { initialPhaseType = initialPhase.getPhaseType(); } } } final DateTime date = plan.dateOfFirstRecurringNonZeroCharge(subscription.getStartDate(), initialPhaseType); final int bcdUTC = date.toDateTime(DateTimeZone.UTC).getDayOfMonth(); final int bcdLocal = date.toDateTime(account.getTimeZone()).getDayOfMonth(); log.info("Calculated BCD: subscription id {}, subscription start {}, timezone {}, bcd UTC {}, bcd local {}", subscription.getId(), date.toDateTimeISO(), account.getTimeZone(), bcdUTC, bcdLocal); return bcdLocal; }
From source file:com.ning.billing.meter.timeline.consumer.AccumulatorSampleConsumer.java
License:Apache License
@Override public void processOneSample(final DateTime time, final SampleOpcode opcode, final Object value) { // Round the sample timestamp according to the aggregation mode final long millis = time.toDateTime(DateTimeZone.UTC).getMillis(); final DateTime roundedTime; switch (timeAggregationMode) { case SECONDS: roundedTime = new DateTime((millis / 1000) * 1000L, DateTimeZone.UTC); break;// w w w . j ava 2 s . com case MINUTES: roundedTime = new DateTime((millis / (60 * 1000)) * 60 * 1000L, DateTimeZone.UTC); break; case HOURS: roundedTime = new DateTime((millis / (60 * 60 * 1000)) * 60 * 60 * 1000L, DateTimeZone.UTC); break; case DAYS: roundedTime = new DateTime((millis / (24 * 60 * 60 * 1000)) * 24 * 60 * 60 * 1000L, DateTimeZone.UTC); break; case MONTHS: roundedTime = new DateTime(time.getYear(), time.getMonthOfYear(), 1, 0, 0, 0, 0, DateTimeZone.UTC); break; case YEARS: roundedTime = new DateTime(time.getYear(), 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); break; default: roundedTime = time; break; } // Get the sample value to aggregate // TODO Should we ignore conversion errors (e.g. Strings)? final double doubleValue = ScalarSample.getDoubleValue(opcode, value); // Output if it's not the first value and the current rounded time differ from the previous one if (lastRoundedTime != null && !lastRoundedTime.equals(roundedTime)) { outputAndResetAccumulators(); } // Perform (or restart) the aggregation if (accumulators.get(opcode) == null) { accumulators.put(opcode, Double.valueOf("0")); } accumulators.put(opcode, accumulators.get(opcode) + doubleValue); lastRoundedTime = roundedTime; }
From source file:com.ning.billing.util.clock.DefaultClock.java
License:Apache License
public static DateTime toUTCDateTime(final DateTime input) { if (input == null) { return null; }/*from w ww . j av a 2 s . co m*/ final DateTime result = input.toDateTime(DateTimeZone.UTC); return truncateMs(result); }
From source file:com.ning.killbill.zuora.zuora.ZuoraDateUtils.java
License:Apache License
/** * Converts DateTime to Zuora's DateTime * @param dateTime DateTime to convert to Zuora's timezone * @return DateTime in Zuora's timezone// w w w.j a v a 2 s. co m */ public static DateTime toDateTime(DateTime dateTime) { return dateTime != null ? dateTime.toDateTime(ZUORA_TZ) : null; }
From source file:com.niroshpg.android.earthquakemonitor.Utility.java
License:Apache License
/** * Helper method to convert the database representation of the date into something to display * to users. As classy and polished a user experience as "20140102" is, we can do better. * * @param context Context to use for resource localization * @param dateStr The db formatted date string, expected to be of the form specified * in Utility.DATE_FORMAT * @return a user-friendly representation of the date. *//*from w w w . j ava 2 s . c o m*/ public static String getFriendlyDayString(Context context, String dateStr) { // The day string for earthquake events uses the following logic: // For today: "Today, June 8" // For tomorrow: "Tomorrow" // For the next 5 days: "Wednesday" (just the day name) // For all days after that: "Mon Jun 8" Date todayDate = new Date(); String todayStr = EarthQuakeDataContract.getDbDateString(todayDate); DateTime inputDateUTC = DateTimeFormat.forPattern(DATETIME_FORMAT).withZone(DateTimeZone.UTC) .parseDateTime(dateStr); // currentTimeZone.inDaylightTime() DateTime inputDateCurrentTZ = inputDateUTC .toDateTime(DateTimeZone.forOffsetMillis(currentTimeZone.getRawOffset())); // If the date we're building the String for is today's date, the format // is "Today, June 24" if (todayStr.equals(dateStr)) { String today = context.getString(R.string.today); int formatId = R.string.format_full_friendly_date; return String.format(context.getString(formatId, today, getFormattedMonthDay(context, dateStr))); } else { DateTimeFormatter shortenedDateTimeFormat = DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss"); return inputDateCurrentTZ.toString(shortenedDateTimeFormat); // } } }
From source file:com.qatickets.domain.common.DateHelper.java
License:Open Source License
public static DateTime toUserTimeZone(UserProfile user, Date dateUTC) { DateTime dt = new DateTime(dateUTC, DateTimeZone.UTC); return dt.toDateTime(user.getDateTimeZone()); }
From source file:com.rincaro.simplejpa.util.AmazonSimpleDBUtil.java
License:Apache License
/** * Encodes date value into string format that can be compared lexicographically * * @param date date value to be encoded/*w w w. j a v a 2 s .c om*/ * @return string representation of the date value */ public static String encodeDateTime(DateTime date) { return date.toDateTime(DateTimeZone.UTC).toString(); }
From source file:com.thoughtworks.studios.shine.cruise.GoDateTime.java
License:Apache License
public static DateTime parseToUTC(String timestampString) throws GoDateTimeException { DateTimeFormatter format = ISODateTimeFormat.dateTimeNoMillis(); DateTime dateTime; try {//from w w w .j av a 2s.c om dateTime = format.parseDateTime(timestampString); } catch (java.lang.IllegalArgumentException e) { // sigh. handle old cruise timestamp format, e.g. 2008-09-19 02:18:39 +0800 format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss Z"); try { dateTime = format.parseDateTime(timestampString); } catch (java.lang.IllegalArgumentException e2) { // give up !! throw new GoDateTimeException("Could not parse datetime " + timestampString, e2); } } return dateTime.toDateTime(DateTimeZone.forID("UTC")); }
From source file:com.thoughtworks.studios.shine.cruise.ZuluDateTimeFormatter.java
License:Apache License
public static String toZuluString(DateTime dateTime) { DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); return format.print(dateTime.toDateTime(DateTimeZone.forID("UTC"))); }
From source file:com.vaushell.superpipes.nodes.shaarli.N_Shaarli.java
License:Open Source License
@Override protected void loop() throws Exception { if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNodeID() + "] read feed "); }//from w w w . j a v a2s .c om final int max = getProperties().getConfigInteger("max"); int count = 0; final Iterator<ShaarliLink> it; if (getProperties().getConfigBoolean("reverse", Boolean.FALSE)) { it = client.searchAllReverseIterator(); } else { it = client.searchAllIterator(); } while (it.hasNext() && count < max) { final ShaarliLink sl = it.next(); if (sl.getUrl() != null && sl.getTitle() != null && (sl.getID() != null || sl.getPermaID() != null)) { // Tags final Tags tags = new Tags(); for (final String tag : sl.getTags()) { tags.add(tag); } setMessage(Message.create(Message.KeyIndex.URI, new URI(sl.getUrl()), Message.KeyIndex.TITLE, sl.getTitle(), Message.KeyIndex.CONTENT, sl.getDescription(), "id-shaarli", sl.getID(), "id-permanent", sl.getPermaID(), "uri-permanent", URI.create(sl.getPermaURL(client.getEndpoint())), Message.KeyIndex.TAGS, tags)); final DateTime dt = client.convertIDstringToDate(sl.getID()); if (dt != null) { dt.toDateTime(DateTimeZone.UTC); getMessage().setProperty(Message.KeyIndex.PUBLISHED_DATE, dt); } sendMessage(); } ++count; } }