convert to base currency
@param decimal $amt
@param int $fcrn_id
@param date $date
@return boolean/amt
494120
public function convertToBase($amt, $fcrn_id, $date,$round = 6) {
        $source = $this->getSysCcmpCurrencySource($date);
        $rate = $this->getCurrencyRate($fcrn_id, $date,$source);
        if ($rate === FALSE) {
            return FALSE;
        }
        
        /**
         * @todo add convert type to fcsr_courrency_source as definition
         */
        if ($source == 2){
            return round($rate * $amt, $round);
        }
        return round($amt/$rate, $round);

        
    }
426793
function DoAuthorization($txnID, $amount = 0, $currency = 'USD', $entity = 'Order') {
    $values['TRANSACTIONID'] = $txnID;
    $values['AMT'] = number_format($amount, 2, '.', ',');
    $values['TRANSACTIONENTITY'] = $entity;
    $values['CURRENCYCODE'] = $currency;
    return $this->_request($values, 'DoAuthorization');
  }
792022
@Override
    public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
        for (ExchangeRateProvider prov : this.providers) {
            try {
                if (prov.isAvailable(conversionQuery)) {
                    ExchangeRate rate = prov.getExchangeRate(conversionQuery);
                    if (Objects.nonNull(rate)) {
                        return rate;
                    }
                }
            } catch (Exception e) {
                throw new CurrencyConversionException(conversionQuery.getBaseCurrency(), conversionQuery.getCurrency(), null,
                    "Rate Provider did not return data though at check before data was flagged as available," +
                        " provider=" + prov.getContext().getProviderName() + ", query=" + conversionQuery, e);
            }
        }
        throw new CurrencyConversionException(conversionQuery.getBaseCurrency(), conversionQuery.getCurrency(), null,
                "All delegate prov iders failed to deliver rate, providers=" + this.providers +
                        ", query=" + conversionQuery);
    }
1335160
public function rates(string $currency, string $date) : Rates
    {
        $rates = $this->getBaseRates($currency, $date);
        if (empty($rates)) {
            $rates = $this->convert($this->download($date));
            if ($currency !== 'EUR') {
                //Set USD base rate
                $this->setBaseRates($rates->convertBaseRatesToUSD());

                if ($currency !== 'USD') {
                    $rates = $rates->convertBaseRateToCurrency($currency);
                    $this->setBaseRates($rates);
                }
            }
            else {
                $this->setBaseRates($rates);
            }
        }

        return $rates;
    }
698130
public function diffInMicroseconds($date = null, $absolute = true)
    {
        $diff = $this->diff($this->resolveCarbon($date));
        $value = (int) round((((($diff->days * static::HOURS_PER_DAY) +
            $diff->h) * static::MINUTES_PER_HOUR +
            $diff->i) * static::SECONDS_PER_MINUTE +
            ($diff->f + $diff->s)) * static::MICROSECONDS_PER_SECOND);

        return $absolute || !$diff->invert ? $value : -$value;
    }
286903
public function floatDiffInYears($date = null, $absolute = true)
    {
        $start = $this;
        $end = $this->resolveCarbon($date);
        $ascending = ($start <= $end);
        $sign = $absolute || $ascending ? 1 : -1;
        if (!$ascending) {
            $_end = $start;
            $start = $end;
            $end = $_end;
            unset($_end);
        }
        $yearsDiff = $start->diffInYears($end);
        /** @var Carbon|CarbonImmutable $floorEnd */
        $floorEnd = $start->copy()->addYears($yearsDiff);

        if ($floorEnd >= $end) {
            return $sign * $yearsDiff;
        }

        /** @var Carbon|CarbonImmutable $startOfYearAfterFloorEnd */
        $startOfYearAfterFloorEnd = $floorEnd->copy()->addYear()->startOfYear();

        if ($startOfYearAfterFloorEnd > $end) {
            return $sign * ($yearsDiff + $floorEnd->floatDiffInDays($end) / $floorEnd->daysInYear);
        }

        return $sign * ($yearsDiff + $floorEnd->floatDiffInDays($startOfYearAfterFloorEnd) / $floorEnd->daysInYear + $startOfYearAfterFloorEnd->floatDiffInDays($end) / $end->daysInYear);
    }
398432
public function diffInRealMinutes($date = null, $absolute = true)
    {
        return (int) ($this->diffInRealSeconds($date, $absolute) / static::SECONDS_PER_MINUTE);
    }
1149245
private static function map($store = null, $orderCurrency = null) {return dfcf(
		function($store = null, $orderCurrency = null) {return [
			self::$BASE => df_currency_base_c($store)
			,self::$ORDER => $orderCurrency ?: df_currency_current_c($store)
		];}
	, func_get_args());}
780912
function _doCapt($oID, $amt = 0, $currency = 'USD') {
    global $db, $messageStack;

    //@TODO: Read current order status and determine best status to set this to
    $new_order_status = (int)MODULE_PAYMENT_AUTHORIZENET_AIM_ORDER_STATUS_ID;
    if ($new_order_status == 0) $new_order_status = 1;

    $proceedToCapture = true;
    $captureNote = strip_tags(zen_db_input($_POST['captnote']));
    if (isset($_POST['captconfirm']) && $_POST['captconfirm'] == 'on') {
    } else {
      $messageStack->add_session(MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CAPTURE_CONFIRM_ERROR, 'error');
      $proceedToCapture = false;
    }
    if (isset($_POST['btndocapture']) && $_POST['btndocapture'] == MODULE_PAYMENT_AUTHORIZENET_AIM_ENTRY_CAPTURE_BUTTON_TEXT) {
      $captureAmt = (float)$_POST['captamt'];
/*
      if ($captureAmt == 0) {
        $messageStack->add_session(MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_INVALID_CAPTURE_AMOUNT, 'error');
        $proceedToCapture = false;
      }
*/
    }
    if (isset($_POST['captauthid']) && trim($_POST['captauthid']) != '') {
      // okay to proceed
    } else {
      $messageStack->add_session(MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_TRANS_ID_REQUIRED_ERROR, 'error');
      $proceedToCapture = false;
    }
    /**
     * Submit capture request to Authorize.net
     */
    if ($proceedToCapture) {
      // Populate an array that contains all of the data to be sent to Authorize.net
      unset($submit_data);
      $submit_data = array(
                           'x_type' => 'PRIOR_AUTH_CAPTURE',
                           'x_amount' => number_format($captureAmt, 2),
                           'x_trans_id' => strip_tags(trim($_POST['captauthid'])),
//                         'x_invoice_num' => $new_order_id,
//                         'x_po_num' => $order->info['po_number'],
//                         'x_freight' => $order->info['shipping_cost'],
//                         'x_tax_exempt' => 'FALSE', /* 'TRUE' or 'FALSE' */
//                         'x_tax' => $order->info['tax'],
                           );

      $response = $this->_sendRequest($submit_data);
      $response_code = $response[0];
      $response_text = $response[3];
      $response_alert = $response_text . ($this->commError == '' ? '' : ' Communications Error - Please notify webmaster.');
      $this->reportable_submit_data['Note'] = $captureNote;
      $this->_debugActions($response);

      if ($response_code != '1' || ($response[0]==1 && $response[2] == 311) ) {
        $messageStack->add_session($response_alert, 'error');
      } else {
        // Success, so save the results
        $sql_data_array = array('orders_id' => (int)$oID,
                                'orders_status_id' => (int)$new_order_status,
                                'date_added' => 'now()',
                                'comments' => 'FUNDS COLLECTED. Auth Code: ' . $response[4] . "\n" . 'Trans ID: ' . $response[6] . "\n" . ' Amount: ' . ($response[9] == 0.00 ? 'Full Amount' : $response[9]) . "\n" . 'Time: ' . date('Y-m-D h:i:s') . "\n" . $captureNote,
                                'customer_notified' => 0
                             );
        zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
        $db->Execute("update " . TABLE_ORDERS  . "
                      set orders_status = '" . (int)$new_order_status . "'
                      where orders_id = '" . (int)$oID . "'");
        $messageStack->add_session(sprintf(MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CAPT_INITIATED, ($response[9] == 0.00 ? 'Full Amount' : $response[9]), $response[6], $response[4]), 'success');
        return true;
      }
    }
    return false;
  }
909083
public function convert(Money $money, $roundingMode = Money::ROUND_HALF_UP)
    {
        if (!$money->getCurrency()->equals($this->baseCurrency)) {
            throw new InvalidArgumentException(
                sprintf('Currencies must match: Money to convert has currency %s, while CurrencyPair has base currency %s.',
                    $money->getCurrency()->getIsoCode(),
                    $this->baseCurrency->getIsoCode()
                )
            );
        }

        return new Money(
            Math::bcround(
                bcmul($money->getAmountString(), $this->ratio, Money::GAAP_PRECISION + 1),
                Money::GAAP_PRECISION,
                $roundingMode
            ),
            $this->counterCurrency
        );
    }
20161
public static Date addYear(Date date, int amt) {
		return addDateField(date,Calendar.YEAR,amt);
	}
1207576
public CurrencyDateCalculatorBuilder<E> ccy2Calendar(final HolidayCalendar<E> ccy2Calendar) {
        if (ccy2Calendar != null) {
            this.ccy2Calendar = ccy2Calendar;
        }
        return this;
    }
399294
public function floatDiffInMinutes($date = null, $absolute = true)
    {
        return $this->floatDiffInSeconds($date, $absolute) / static::SECONDS_PER_MINUTE;
    }
561091
public function dateTransform($date_value, $format_origin = 'd/m/Y H:i:s', $format_destiny = 'Y-m-d H:i:s')
    {
        $date = \DateTime::createFromFormat($format_origin, $date_value);
        return $date !== false ? $date->format($format_destiny) : '';
    }
603103
def convert_currency(self, base_fiat, base_amount, target_fiat):
        
        url = "http://api.fixer.io/latest?base=%s" % base_fiat
        data = self.get_url(url).json()
        try:
            return data['rates'][target_fiat.upper()] * base_amount
        except KeyError:
            raise Exception("Can not convert %s to %s" % (base_fiat, target_fiat))
275567
protected function createRate(CurrencyPairContract $currencyPair, float $rate, \DateTimeInterface $date): ExchangeRate
    {
        return new ExchangeRate($currencyPair, $rate, $date, $this->getName());
    }
546449
public function getCurrencyRate($id, $date, $source = FALSE) {
        
        
        $this->sError = FALSE;

        if(empty($date)){
            $this->sError = "Date can not be empty.";            
            return FALSE;
        }        
        
        /**
         * validate input param
         */
        if (!$this->isValidCurrencyId($id)) {
            return FALSE;
        }
        
        //same currency no convert
//        $base_fcrn_id = $this->getSysCcmpBaseCurrency($date);
//        if($id == $base_fcrn_id){
//            return 1;
//        }
        
        if ($source) {
            if (!$this->isValidSourceId($source)) {
                return FALSE;
            }
        } else {
            $source = $this->getSysCcmpCurrencySource($date);
        }

        $base = $this->getSourceBaseCurrency($source);
        if($id == $base){
            return 1;
        }
        
        $sSql = "SELECT IF(DATEDIFF('" . $date . "',CURDATE())>1, 1, 0) in_future ";
        $result = Yii::app()->db->createCommand($sSql)->queryScalar();
        if ($result == 1) {
            $this->sError = "Can not get currency rate, Date(" . $date . ") is in future.";
            return FALSE;
        }


        $rate = $this->_getRateFromDb($source, $base, $id, $date);

        /**
         * load rates
         */
        if ($rate) {
            return $rate;
        }
         /**
         * @todo add convert type to fcsr_courrency_source as definition 
         * and implement it in $this->convertFromTo
         */
        switch ($source) {
            case self::SOURCE_BANK_LV:
                $aRate = $this->_getRateFromBankLv($date);
                if (!$aRate) {
                    return FALSE;
                }
                break;
            case self::SOURCE_BANK_LT:
                $aRate = $this->_getRateFromBankLt($date);
                if (!$aRate) {
                    return FALSE;
                }
                break;
            case self::SOURCE_BANK_RU:
                $aRate = $this->_getRateFromBankRu($date);
                if (!$aRate) {
                    return FALSE;
                }
                break;
            case self::SOURCE_BANK_LT_ACC_EUR:
                $aRate = $this->_getRateFromBankLtAccEur($date);
                if (!$aRate) {
                    return FALSE;
                }
                break;
            default:
                $this->sError = "Undefined currency source: " .$source;
                return false;
                break;
         }

        $this->_saveRate($aRate, $date, $source);

        return $this->_getRateFromDb($source, $base, $id, $date);
    }