Example usage for org.joda.time DateTimeZone UTC

List of usage examples for org.joda.time DateTimeZone UTC

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone UTC.

Prototype

DateTimeZone UTC

To view the source code for org.joda.time DateTimeZone UTC.

Click Source Link

Document

The time zone for Universal Coordinated Time

Usage

From source file:com.ning.arecibo.util.timeline.DateTimeUtils.java

License:Apache License

public static int unixSeconds(final DateTime dateTime) {
    final long millis = dateTime.toDateTime(DateTimeZone.UTC).getMillis();
    return (int) (millis / 1000L);
}

From source file:com.ning.billing.analytics.dao.BusinessAccountMapper.java

License:Apache License

@Override
public BusinessAccountModelDao map(final int index, final ResultSet r, final StatementContext ctx)
        throws SQLException {
    return new BusinessAccountModelDao(UUID.fromString(r.getString(1)), r.getString(2), r.getString(6),
            BigDecimal.valueOf(r.getDouble(5)), getDate(r, "last_invoice_date"),
            BigDecimal.valueOf(r.getDouble(8)), r.getString(9), r.getString(10), r.getString(11),
            r.getString(12), r.getString(13), new DateTime(r.getLong(3), DateTimeZone.UTC),
            new DateTime(r.getLong(4), DateTimeZone.UTC));
}

From source file:com.ning.billing.analytics.dao.BusinessInvoiceItemMapper.java

License:Apache License

@Override
public BusinessInvoiceItemModelDao map(final int index, final ResultSet r, final StatementContext ctx)
        throws SQLException {
    final UUID itemId = getUUID(r, "item_id");
    final UUID linkedItemId = getUUID(r, "linked_item_id");
    final DateTime createdDate = new DateTime(r.getLong("created_date"), DateTimeZone.UTC);
    final DateTime updatedDate = new DateTime(r.getLong("updated_date"), DateTimeZone.UTC);
    final UUID invoiceId = getUUID(r, "invoice_id");
    final String itemType = r.getString("item_type");
    final String externalKey = r.getString("external_key");
    final String productName = r.getString("product_name");
    final String productType = r.getString("product_type");
    final String productCategory = r.getString("product_category");
    final String slug = r.getString("slug");
    final String phase = r.getString("phase");
    final String billingPeriod = r.getString("billing_period");
    final LocalDate startDate = getDate(r, "start_date");
    final LocalDate endDate = getDate(r, "end_date");
    final BigDecimal amount = BigDecimal.valueOf(r.getDouble("amount"));
    final Currency currency = Currency.valueOf(r.getString("currency"));

    return new BusinessInvoiceItemModelDao(amount, billingPeriod, createdDate, currency, endDate, externalKey,
            invoiceId, itemId, linkedItemId, itemType, phase, productCategory, productName, productType, slug,
            startDate, updatedDate);//from  ww  w . j a va  2s . c  o  m
}

From source file:com.ning.billing.analytics.dao.BusinessInvoiceMapper.java

License:Apache License

@Override
public BusinessInvoiceModelDao map(final int index, final ResultSet r, final StatementContext ctx)
        throws SQLException {
    final UUID invoiceId = UUID.fromString(r.getString(1));
    final Integer invoiceNumber = r.getInt(2);
    final DateTime createdDate = new DateTime(r.getLong(3), DateTimeZone.UTC);
    final DateTime updatedDate = new DateTime(r.getLong(4), DateTimeZone.UTC);
    final UUID accountId = UUID.fromString(r.getString(5));
    final String accountKey = r.getString(6);
    final LocalDate invoiceDate = getDate(r, "invoice_date");
    final LocalDate targetDate = getDate(r, "target_date");
    final Currency currency = Currency.valueOf(r.getString(9));
    final BigDecimal balance = BigDecimal.valueOf(r.getDouble(10));
    final BigDecimal amountPaid = BigDecimal.valueOf(r.getDouble(11));
    final BigDecimal amountCharged = BigDecimal.valueOf(r.getDouble(12));
    final BigDecimal amountCredited = BigDecimal.valueOf(r.getDouble(13));

    return new BusinessInvoiceModelDao(accountId, accountKey, amountCharged, amountCredited, amountPaid,
            balance, createdDate, currency, invoiceDate, invoiceId, invoiceNumber, targetDate, updatedDate);
}

From source file:com.ning.billing.analytics.dao.BusinessInvoicePaymentMapper.java

License:Apache License

@Override
public BusinessInvoicePaymentModelDao map(final int index, final ResultSet r, final StatementContext ctx)
        throws SQLException {
    final UUID paymentId = UUID.fromString(r.getString(1));
    final DateTime createdDate = new DateTime(r.getLong(2), DateTimeZone.UTC);
    final DateTime updatedDate = new DateTime(r.getLong(3), DateTimeZone.UTC);
    final String extFirstPaymentRefId = r.getString(4);
    final String extSecondPaymentRefId = r.getString(5);
    final String accountKey = r.getString(6);
    final UUID invoiceId = UUID.fromString(r.getString(7));
    final DateTime effectiveDate = new DateTime(r.getLong(8), DateTimeZone.UTC);
    final BigDecimal amount = BigDecimal.valueOf(r.getDouble(9));
    final Currency currency = Currency.valueOf(r.getString(10));
    final String paymentError = r.getString(11);
    final String processingStatus = r.getString(12);
    final BigDecimal requestedAmount = BigDecimal.valueOf(r.getDouble(13));
    final String pluginName = r.getString(14);
    final String paymentType = r.getString(15);
    final String paymentMethod = r.getString(16);
    final String cardType = r.getString(17);
    final String cardCountry = r.getString(18);
    final String invoicePaymentType = r.getString(19);
    final String linkedInvoicePaymentIdString = r.getString(20);

    final UUID linkedInvoicePaymentId;
    if (linkedInvoicePaymentIdString != null) {
        linkedInvoicePaymentId = UUID.fromString(linkedInvoicePaymentIdString);
    } else {// w w  w.  jav a  2s  .c  o m
        linkedInvoicePaymentId = null;
    }

    return new BusinessInvoicePaymentModelDao(accountKey, amount, cardCountry, cardType, createdDate, currency,
            effectiveDate, invoiceId, paymentError, paymentId, paymentMethod, paymentType, pluginName,
            processingStatus, requestedAmount, updatedDate, invoicePaymentType, linkedInvoicePaymentId);
}

From source file:com.ning.billing.analytics.dao.BusinessOverdueStatusMapper.java

License:Apache License

@Override
public BusinessOverdueStatusModelDao map(final int index, final ResultSet r, final StatementContext ctx)
        throws SQLException {
    final UUID bundleId = UUID.fromString(r.getString(1));
    final String externalKey = r.getString(2);
    final String accountKey = r.getString(3);
    final String status = r.getString(4);
    final DateTime startDate = new DateTime(r.getLong(5), DateTimeZone.UTC);
    final DateTime endDate = new DateTime(r.getLong(6), DateTimeZone.UTC);

    return new BusinessOverdueStatusModelDao(accountKey, bundleId, endDate, externalKey, startDate, status);
}

From source file:com.ning.billing.analytics.dao.BusinessSubscriptionTransitionMapper.java

License:Apache License

@Override
public BusinessSubscriptionTransitionModelDao map(final int index, final ResultSet r,
        final StatementContext ctx) throws SQLException {
    BusinessSubscription prev = new BusinessSubscription(r.getString(9), // productName
            r.getString(10), // productType
            r.getString(11) == null ? null : ProductCategory.valueOf(r.getString(11)), // productCategory
            r.getString(12), // slug
            r.getString(13), // phase
            r.getString(14), // billing period
            BigDecimal.valueOf(r.getDouble(15)), // price
            r.getString(16), // priceList
            BigDecimal.valueOf(r.getDouble(17)), // mrr
            r.getString(18), // currency
            r.getLong(19) == 0 ? null : new DateTime(r.getLong(19), DateTimeZone.UTC), // startDate
            r.getString(20) == null ? null : SubscriptionState.valueOf(r.getString(20)) // state
    );/*from w w w. j  a  v  a 2 s.  c om*/

    // Avoid creating a dummy subscriptions with all null fields
    if (prev.getProductName() == null && prev.getSlug() == null) {
        prev = null;
    }

    BusinessSubscription next = new BusinessSubscription(r.getString(21), // productName
            r.getString(22), // productType
            r.getString(23) == null ? null : ProductCategory.valueOf(r.getString(23)), // productCategory
            r.getString(24), // slug8
            r.getString(25), // phase
            r.getString(26), // billing period
            BigDecimal.valueOf(r.getDouble(27)), // price
            r.getString(28), // priceList
            BigDecimal.valueOf(r.getDouble(29)), // mrr
            r.getString(30), // currency
            r.getLong(31) == 0 ? null : new DateTime(r.getLong(31), DateTimeZone.UTC), // startDate
            r.getString(32) == null ? null : SubscriptionState.valueOf(r.getString(32)) // state
    );

    // Avoid creating a dummy subscriptions with all null fields
    if (next.getProductName() == null && next.getSlug() == null) {
        next = null;
    }

    final BusinessSubscriptionEvent event = BusinessSubscriptionEvent.valueOf(r.getString(8));

    return new BusinessSubscriptionTransitionModelDao(r.getLong(1), UUID.fromString(r.getString(2)),
            r.getString(3), UUID.fromString(r.getString(4)), r.getString(5), UUID.fromString(r.getString(6)),
            new DateTime(r.getLong(7), DateTimeZone.UTC), event, prev, next);
}

From source file:com.ning.billing.beatrix.util.InvoiceChecker.java

License:Apache License

public void checkChargedThroughDate(final UUID subscriptionId, final LocalDate expectedLocalCTD,
        final CallContext context) {
    try {/*w  w w .  j  a  va  2 s .  co m*/
        final Subscription subscription = entitlementApi.getSubscriptionFromId(subscriptionId, context);
        if (expectedLocalCTD == null) {
            assertNull(subscription.getChargedThroughDate());
        } else {
            final DateTime expectedCTD = expectedLocalCTD.toDateTime(
                    new LocalTime(subscription.getStartDate().getMillis(), DateTimeZone.UTC), DateTimeZone.UTC);
            final String msg = String.format(
                    "Checking CTD for subscription %s : expectedLocalCTD = %s => expectedCTD = %s, got %s",
                    subscriptionId, expectedLocalCTD, expectedCTD, subscription.getChargedThroughDate());
            log.info(msg);
            assertNotNull(subscription.getChargedThroughDate());
            assertTrue(subscription.getChargedThroughDate().compareTo(expectedCTD) == 0, msg);
        }
    } catch (EntitlementUserApiException e) {
        fail("Failed to retrieve subscription for " + subscriptionId);
    }
}

From source file:com.ning.billing.invoice.api.MockInvoicePaymentApi.java

License:Apache License

@Override
public InvoicePayment createChargeback(final UUID invoicePaymentId, final BigDecimal amount,
        final CallContext context) throws InvoiceApiException {
    InvoicePayment existingPayment = null;
    for (final InvoicePayment payment : invoicePayments) {
        if (payment.getId() == invoicePaymentId) {
            existingPayment = payment;//w  ww  .j  a  v  a  2  s . c om
            break;
        }
    }

    if (existingPayment != null) {
        invoicePayments.add(new DefaultInvoicePayment(UUID.randomUUID(), InvoicePaymentType.CHARGED_BACK, null,
                null, DateTime.now(DateTimeZone.UTC), amount, Currency.USD, null, existingPayment.getId()));
    }

    return existingPayment;
}

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  va 2  s  . c om
    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;
}