valutas kurrs valūtai uz konkrēto datumu
@param int $nId currency id
@param date $dDate format yyyy.mm.dd
@return boolean|float - currency rate
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);
    }
870674
public function currSessData($nID, $tbl, $fld = '', $action = 'get', $newVal = null, $hasParManip = false, 
        $itemInd = -3, $itemID = -3)
    {
        if (trim($tbl) == '' || trim($fld) == '' || !$this->loaded) {
            return '';
        }
        if (in_array($nID, $this->checkboxNodes) && $GLOBALS["SL"]->isFldCheckboxHelper($fld)) {
            $tblFld = $tbl . '-' . $fld;
            $this->helpInfo[$tblFld] = $this->getCheckboxHelperInfo($tbl, $fld);
            if ($this->helpInfo[$tblFld]["link"] && isset($this->helpInfo[$tblFld]["link"]->DataHelpValueField)) {
                return $this->currSessDataCheckbox($nID, $tbl, $fld);
            }
        }
        if ($itemInd < 0 || $itemID <= 0) {
            list($itemInd, $itemID) = $this->currSessDataPos($tbl, $hasParManip);
        }
        if ($itemInd < 0 || $itemID <= 0) {
            return '';
        }
        if ($action == 'get') {
            if ($this->dataFieldExists($tbl, $itemInd, $fld)) {
                return $this->dataSets[$tbl][$itemInd]->{ $fld };
            }
        } elseif ($action == 'update' && $fld != ($GLOBALS["SL"]->tblAbbr[$tbl] . 'ID')) {
            $this->logDataSave($nID, $tbl, $itemID, $fld, $newVal);
            if (trim($newVal) == '' && in_array($GLOBALS["SL"]->fldTypes[$tbl][$fld], ['INT', 'DOUBLE'])) {
                $newVal = null;
            } elseif ($GLOBALS["SL"]->fldTypes[$tbl][$fld] == 'INT') {
                $newVal = intVal($newVal);
            } elseif ($GLOBALS["SL"]->fldTypes[$tbl][$fld] == 'DOUBLE') {
                $newVal = floatval($newVal);
            } else {
                $newVal = strip_tags($newVal);
            }
            if (isset($this->dataSets[$tbl]) && isset($this->dataSets[$tbl][$itemInd])) {
                $this->dataSets[$tbl][$itemInd]->{ $fld } = $newVal;
                $this->dataSets[$tbl][$itemInd]->save();
                return $newVal;
            } else {
              //$GLOBALS["errors"] .= 'Couldn\'t find dataSets[' . $tbl . '][' . $itemInd . '] for ' . $fld . '<br />';
            }
        }
        return $newVal;
    }
1078796
public static Date getDateFromTransactionId(long txnId) {
        long time = txnId >> (COUNTER_BITS + INITIATORID_BITS);
        time += VOLT_EPOCH;
        return new Date(time);
    }
1276793
private DateTime parseToDate(String toDate) {
        // Default to now
        return parseDate(toDate, new DateTime().withZone(DateTimeZone.UTC), false);
    }
546292
public static Date parseDate(final String pDate) throws ParseException {

        final SimpleDateFormat format = new SimpleDateFormat(OCCURRENCE_DATE_FORMAT);
        return format.parse(pDate);
    }
574683
public function loadNodeCache($nID = -3, $nCache = [])
    {
        if (sizeof($nCache) > 0) {
            if (isset($nCache["pID"])) {
                $this->parentID = $nCache["pID"];
            }
            if (isset($nCache["pOrd"])) {
                $this->parentOrd = $nCache["pOrd"];
            }
            if (isset($nCache["opts"])) {
                $this->nodeOpts = $nCache["opts"];
            }
            if (isset($nCache["type"])) {
                $this->nodeType = $nCache["type"];
            }
            if (isset($nCache["branch"])) {
                $this->dataBranch = $nCache["branch"];
            }
            if (isset($nCache["store"])) {
                $this->dataStore = $nCache["store"];
            }
            if (isset($nCache["set"])) {
                $this->responseSet = $nCache["set"];
            }
            if (isset($nCache["def"])) {
                $this->defaultVal = $nCache["def"];
            }
        }
        return true;
    }
396271
public function diffInYears(Date $dt = null, $abs = true)
    {
        $dt = $dt ?: static::now($this->getTimezone());

        return (int) $this->diff($dt, $abs)->format('%r%y');
    }
593090
public function getRates(\DateTime $date = null)
    {
        if (null === $date) {
            $date = new \DateTime();
        }

        // Pokud je pozadan kurz pro dnesni den a jeste nebylo 14:15 zverejnim vcerejsi kurz
        if ($date->format('Hi') < 1415) {
            $date->modify('-1 day');
        }

        $cachedFileName = $date->format('Ymd').'.php';

        if (!is_dir($this->cacheDir)) {
            mkdir($this->cacheDir);
        }

        $cachedFile = $this->cacheDir.'/cnb_'.$cachedFileName;

        if (!is_file($cachedFile)) {
            $url = sprintf(self::API_URL, urlencode($date->format('d.m.Y')));
            $file = explode("\n", file_get_contents($url));

            $rates = [];

            foreach ($file as $index => $line) {
                // Datum a hlavicku souboru preskocime
                if ($index < 2) {
                    continue;
                }
                // Pokud je radek prazdny
                if (empty($line)) {
                    continue;
                }
                $rate = explode('|', $line);

                $rates[$rate[3]] = new Rate(
                    $date,
                    $rate[3],
                    $rate[0],
                    $rate[1],
                    Lib::toNumber($rate[2]),
                    Lib::toNumber($rate[4])
                );
            }
            file_put_contents($cachedFile, serialize($rates));
        } else {
            $rates = unserialize(file_get_contents($cachedFile));
        }

        // Prevedeni do objektu Rates pro lepsi pristup v sablonach
        return new Rates($date, $rates);
    }
709347
public static function format($pDate, $pFormat = 'short')
    {
    	switch ($pFormat) {
    		case 'short':
    			return strftime('%x', strtotime($pDate));
    			break;
    		case 'long':
    			return strftime('%x %H:%M', strtotime($pDate));
    			break;
    		case 'full':
    			return strftime('%x %H:%M:%S', strtotime($pDate));
    			break;
    	}

    	throw new Exception("The requested date format is not correct");
    }
806901
public static function prevDate($date, $interval = 1, $newFormat = "Y-m-d")
    {
        $x            = $this->splitDate($date, 'int');
        $unixTime     = date("U", mktime(1, 0, 0, $x['month'], $x['date'], $x['year']));
        $sehari       = 24 * 60 * 60;
        $prevUnixTime = $unixTime - ($sehari * $interval);

        return date($newFormat, $prevUnixTime);
    }
942256
private function _getRateFromDb($source, $base, $id, $date) {

        $rate = Yii::app()->db->createCommand()
                ->select('fcrt_rate')
                ->from('fcrt_currency_rate')
                ->where('
                    fcrt_fcsr_id=:source 
                    AND fcrt_base_fcrn_id=:base
                    and fcrt_fcrn_id=:id
                    and fcrt_date=:date', array(
                    ':source' => $source,
                    ':base' => $base,
                    ':id' => $id,
                    ':date' => $date
                ))
                ->queryScalar();


        if (!$rate) {
            return FALSE;
        }
        return $rate;
    }
1313610
public function getDateFormat($includeYear = TRUE, $includeDate = TRUE) {
        $returnVar = $this->getCurrentFormat();
        if(!$includeYear) {
            if(preg_match('@^Y@', $returnVar)) {
                $returnVar = substr($returnVar, 2); //If it starts with the year
            } elseif(preg_match('@Y$@', $returnVar)) {
                $returnVar = substr($returnVar, 0, -2); //If ends with the year
            } else {
                $returnVar = preg_replace('@Y.@', '', $returnVar); //If in middle if year
            }
        }
        if(!$includeDate) {
            if(preg_match('@^d@', $returnVar)) {
                $returnVar = substr($returnVar, 2); //If it starts with the year
            } elseif(preg_match('@d$@', $returnVar)) {
                $returnVar = substr($returnVar, 0, -2); //If ends with the year
            } else {
                $returnVar = preg_replace('@d.@', '', $returnVar); //If in middle if year
            }
        }
        return $returnVar;
    }
456208
public static double estimate(final GregorianCalendar forDate) {
        final double year = decimalYear(forDate);
        final double deltaT;

        if (year < -500) {
            double u = (year - 1820) / 100;
            deltaT = -20 + 32 * pow(u, 2);
        } else if (year < 500) {
            double u = year / 100;
            deltaT = 10583.6 - 1014.41 * u + 33.78311 * pow(u, 2) - 5.952053 * pow(u, 3)
                    - 0.1798452 * pow(u, 4) + 0.022174192 * pow(u, 5) + 0.0090316521 * pow(u, 6);
        } else if (year < 1600) {
            double u = (year - 1000) / 100;
            deltaT = 1574.2 - 556.01 * u + 71.23472 * pow(u, 2) + 0.319781 * pow(u, 3)
                    - 0.8503463 * pow(u, 4) - 0.005050998 * pow(u, 5) + 0.0083572073 * pow(u, 6);
        } else if (year < 1700) {
            double t = year - 1600;
            deltaT = 120 - 0.9808 * t - 0.01532 * pow(t, 2) + pow(t, 3) / 7129;
        } else if (year < 1800) {
            double t = year - 1700;
            deltaT = 8.83 + 0.1603 * t - 0.0059285 * pow(t, 2) + 0.00013336 * pow(t, 3) - pow(t, 4) / 1174000;
        } else if (year < 1860) {
            double t = year - 1800;
            deltaT = 13.72 - 0.332447 * t + 0.0068612 * pow(t, 2) + 0.0041116 * pow(t, 3) - 0.00037436 * pow(t, 4)
                    + 0.0000121272 * pow(t, 5) - 0.0000001699 * pow(t, 6) + 0.000000000875 * pow(t, 7);
        } else if (year < 1900) {
            double t = year - 1860;
            deltaT = 7.62 + 0.5737 * t - 0.251754 * pow(t, 2) + 0.01680668 * pow(t, 3)
                    - 0.0004473624 * pow(t, 4) + pow(t, 5) / 233174;
        } else if (year < 1920) {
            double t = year - 1900;
            deltaT = -2.79 + 1.494119 * t - 0.0598939 * pow(t, 2) + 0.0061966 * pow(t, 3) - 0.000197 * pow(t, 4);
        } else if (year < 1941) {
            double t = year - 1920;
            deltaT = 21.20 + 0.84493 * t - 0.076100 * pow(t, 2) + 0.0020936 * pow(t, 3);
        } else if (year < 1961) {
            double t = year - 1950;
            deltaT = 29.07 + 0.407 * t - pow(t, 2) / 233 + pow(t, 3) / 2547;
        } else if (year < 1986) {
            double t = year - 1975;
            deltaT = 45.45 + 1.067 * t - pow(t, 2) / 260 - pow(t, 3) / 718;
        } else if (year < 2005) {
            double t = year - 2000;
            deltaT = 63.86 + 0.3345 * t - 0.060374 * pow(t, 2) + 0.0017275 * pow(t, 3) + 0.000651814 * pow(t, 4)
                    + 0.00002373599 * pow(t, 5);
        } else if (year < 2050) {
            double t = year - 2000;
            deltaT = 62.92 + 0.32217 * t + 0.005589 * pow(t, 2);
        } else if (year < 2150) {
            deltaT = -20 + 32 * pow(((year - 1820) / 100), 2) - 0.5628 * (2150 - year);
        } else {
            double u = (year - 1820) / 100;
            deltaT = -20 + 32 * pow(u, 2);
        }


        return deltaT;

    }
244287
public function get($idSite, $period, $date, $segment = false, $columns = false)
    {
        Piwik::checkUserHasViewAccess($idSite);

        $report = ReportsProvider::factory("Actions", "get");
        $archive = Archive::build($idSite, $period, $date, $segment);

        $requestedColumns = Piwik::getArrayFromApiParameter($columns);
        $columns = $report->getMetricsRequiredForReport($allColumns = null, $requestedColumns);

        $inDbColumnNames = array_map(function ($value) { return 'Actions_' . $value; }, $columns);
        $dataTable = $archive->getDataTableFromNumeric($inDbColumnNames);

        $dataTable->deleteColumns(array_diff($requestedColumns, $columns));

        $newNameMapping = array_combine($inDbColumnNames, $columns);
        $dataTable->filter('ReplaceColumnNames', array($newNameMapping));

        $columnsToShow = $requestedColumns ?: $report->getAllMetrics();
        $dataTable->queueFilter('ColumnDelete', array($columnsToRemove = array(), $columnsToShow));

        return $dataTable;
    }
1294681
protected function getDataTable($idSite, $period, $date, $segment, $expanded, $flat, $idSubtable)
    {
        $dataTable = Archive::createDataTableFromArchive(Archiver::CUSTOM_VARIABLE_RECORD_NAME, $idSite, $period, $date, $segment, $expanded, $flat, $idSubtable);
        $dataTable->queueFilter('ColumnDelete', 'nb_uniq_visitors');

        if ($flat) {
            $dataTable->filterSubtables('Sort', array(Metrics::INDEX_NB_ACTIONS, 'desc', $naturalSort = false, $expanded));
            $dataTable->queueFilterSubtables('ColumnDelete', 'nb_uniq_visitors');
        }

        return $dataTable;
    }
784819
public final void mDATE() throws RecognitionException {
		try {
			int _type = DATE;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// druidG.g:680:2: ( DATE_YEAR_MONTH_ONLY '-' NUM NUM )
			// druidG.g:680:4: DATE_YEAR_MONTH_ONLY '-' NUM NUM
			{
			mDATE_YEAR_MONTH_ONLY(); 

			match('-'); 
			mNUM(); 

			mNUM(); 

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
1203673
static public function getPeriode($startDate, $endDate = null, $nbMoisGlissant = false)
    {
        $dtStart = Datetime::getInstance();
        $dtEnd = Datetime::getInstance();
        
        $dtStart->set_date($startDate);
        $dtEnd->set_date(is_null($endDate) ? $startDate : $endDate);
        
        /*
         * Test si mois glissant
         */
        if ($dtStart->equals($dtEnd) === 0 && $nbMoisGlissant) {
            $dtStart->sub_month($nbMoisGlissant - 1);
        }
        
        if ($dtStart->equals($dtEnd) === 0) {
            $lib_periode = $dtStart->format('%B %Y');
            $shortlib_periode = $dtStart->format('%b %Y');
        }
        else {
            $lib_periode = $dtStart->format('%B %Y') . ' - ' . $dtEnd->format('%B %Y');
            $shortlib_periode = $dtStart->format('%b %Y') . ' - ' . $dtEnd->format('%b %Y');
        }
        
        $result = [
            'lib'      => $lib_periode,
            'shortlib' => $shortlib_periode,
            'start'    => $dtStart,
            'end'      => $dtEnd,
        ];
        
        return $result;
    }