| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.utils.currency; |
| |
| import java.text.ParseException; |
| import java.util.Currency; |
| |
| import org.joda.money.CurrencyUnit; |
| import org.joda.time.DateTime; |
| import org.joda.time.format.DateTimeFormat; |
| import org.joda.time.format.DateTimeFormatter; |
| |
| /** |
| * utilities for currency and currency units |
| */ |
| public class Utilities { |
| |
| private static DateTimeFormatter REFERENCE_DATE_FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd"); |
| |
| /** |
| * @param referenceDate in the format YYYY-MM-DD |
| * @return the corresponding Calendar instance for the referenceDate |
| * @throws ParseException |
| */ |
| public static DateTime toIndexingDateTime(String referenceDate) throws ParseException { |
| return DateTime.parse(referenceDate, REFERENCE_DATE_FORMAT); |
| } |
| |
| public static DateTime toIndexingDateTime(DateTime referenceDate) { |
| return new DateTime(referenceDate.getYear(), referenceDate.getMonthOfYear(), referenceDate.getDayOfMonth(), 0, 0); |
| } |
| |
| /** |
| * @param currencyUnit |
| * @return return CurrencyUnit instance for the parameter given |
| */ |
| public static CurrencyUnit of(CurrencyUnit currencyUnit) { |
| return currencyUnit; |
| } |
| |
| /** |
| * @param currency |
| * @return return CurrencyUnit instance for the parameter given |
| */ |
| public static CurrencyUnit of(Currency currency) { |
| return CurrencyUnit.of(currency); |
| } |
| |
| /** |
| * @param currencyIso4217 as defined in ISO-4217 |
| * @return return CurrencyUnit instance for the parameter given |
| */ |
| public static CurrencyUnit of(String currencyIso4217) { |
| return CurrencyUnit.of(currencyIso4217); |
| } |
| } |