Get date component from an array by key as an integer.

@param array  $aDate       Date components as array.
@param int    $iKey        Date component index.
@param string $sZeroString A zero representing string value, default is "00".

@return int
502551
protected function _getDateComponentAsInteger( $aDate, $iKey, $sZeroString = '00' )
    {
        if ( empty( $aDate[$iKey] ) or ( $aDate[$iKey] == $sZeroString ) ) {
            return 0;
        }

        return (int) $aDate[$iKey];
    }
1276793
private DateTime parseToDate(String toDate) {
        // Default to now
        return parseDate(toDate, new DateTime().withZone(DateTimeZone.UTC), false);
    }
972723
public function getById($iId, $aData = [])
    {
        if (empty($aData['where'])) {
            $aData['where'] = [];
        }

        $aData['where'][] = [$this->sTableAlias . '.id', $iId];

        $aEmails = $this->getAll(null, null, $aData);

        return !empty($aEmails) ? reset($aEmails) : false;
    }
326005
protected function getCountCommon(array $aData = [])
    {
        //  @deprecated - searching should use the search() method, but this in place
        //  as a quick fix for loads of admin controllers
        if (!empty($aData['keywords']) && !empty($this->searchableFields)) {
            if (empty($aData['or_like'])) {
                $aData['or_like'] = [];
            }

            $sAlias = $this->getTableAlias(true);

            foreach ($this->searchableFields as $mField) {

                //  If the field is an array then search across the columns concatenated together
                if (is_array($mField)) {

                    $sMappedFields = array_map(function ($sInput) use ($sAlias) {
                        if (strpos($sInput, '.') !== false) {
                            return $sInput;
                        } else {
                            return $sAlias . $sInput;
                        }
                    }, $mField);

                    $aData['or_like'][] = ['CONCAT_WS(" ", ' . implode(',', $sMappedFields) . ')', $aData['keywords']];

                } else {
                    if (strpos($mField, '.') !== false) {
                        $aData['or_like'][] = [$mField, $aData['keywords']];
                    } else {
                        $aData['or_like'][] = [$sAlias . $mField, $aData['keywords']];
                    }
                }
            }
        }

        // --------------------------------------------------------------------------

        $this->getCountCommonCompileSelect($aData);
        $this->getCountCommonCompileFilters($aData);
        $this->getCountCommonCompileWheres($aData);
        $this->getCountCommonCompileLikes($aData);
        $this->getCountCommonCompileHavings($aData);
        $this->getCountCommonCompileSort($aData);
    }
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
		}
	}
1006888
public static function pf_date_assoc($from, $to, $default = null, $step = '+1 day', $outputFormat = 'Y-m-d')
    {
        $dates = self::pf_date_indexed($from, $to, $step, $outputFormat);
        return array_fill_keys($dates, $default);
    }
381745
public static function a2sUpdate($iArray, $defaultArray = array()) {

        $str = "";
//        self::pln($iArray,"ns");
        while (list($key, $val) = each($iArray)) {
//            self::pln(gettype($val),"t=$key");
            // override value from $defaultArray value of the same key
            if (empty($val) and isset($defaultArray[$key])) {
                // set to value of $defaultArray when value is empty
               $val = $defaultArray[$key]; 
            // catch the case of integer val=0
            } elseif (isset($val) and empty($val) and gettype($val)<>"string") {
               $val = $val;
            } else {
               $val = self::escapeQuote($val);
            } 
            // concat fields list for sql update
            // use single quote to work around sqlsrv error
            $str .= $key . " ='" . $val . "', ";
//            self::pln($str,"vs");
        }
        // return maker= 'Name', acct= '15',
        return substr($str, 0, strlen($str) - 2); // take out comma and space
    }
1179765
public void addFloatingDate(ICalProperty property, ICalDate date) {
		floatingDates.add(new TimezonedDate(date, property));
	}
1107776
public function getById($iId, array $aData = [])
    {
        if (!$this->tableIdColumn) {
            throw new ModelException(static::class . '::getById() Column variable not set.', 1);
        }

        return $this->getByColumn($this->tableIdColumn, $iId, $aData);
    }
57615
protected function getCountCommonCompileWheres(array &$aData)
    {
        $oDb = Factory::service('Database');

        /**
         * Handle where's
         *
         * This is an array of the various type of where that can be passed in via $aData.
         * The first element is the key and the second is how multiple items within the
         * group should be glued together.
         *
         * Each type of where is grouped in it's own set of parenthesis, multiple groups
         * are glued together with ANDs
         */

        $aWheres = [
            'where'           => 'AND',
            'or_where'        => 'OR',
            'where_in'        => 'AND',
            'or_where_in'     => 'OR',
            'where_not_in'    => 'AND',
            'or_where_not_in' => 'OR',
        ];

        $aWhereCompiled = [];

        foreach ($aWheres as $sWhereType => $sWhereGlue) {

            if (!empty($aData[$sWhereType])) {

                $aWhereCompiled[$sWhereType] = [];

                if (is_array($aData[$sWhereType])) {

                    /**
                     * The value is an array. For each element we need to compile as appropriate
                     * and add to $aWhereCompiled.
                     */

                    foreach ($aData[$sWhereType] as $mWhere) {

                        if (is_string($mWhere)) {

                            /**
                             * The value is a straight up string, assume this is a compiled
                             * where string,
                             */

                            $aWhereCompiled[$sWhereType][] = $mWhere;

                        } else {

                            /**
                             * The value is an array, try and determine the various parts
                             * of the query. We use strings which are unlikely to be found
                             * as falsey values (such as null) are perfectly likely.
                             */

                            //  Work out column
                            $mColumn = isset($mWhere['column']) ? $mWhere['column'] : '[NAILS-COL-NOT-FOUND]';

                            if ($mColumn === '[NAILS-COL-NOT-FOUND]') {
                                $mColumn = isset($mWhere[0]) && is_string($mWhere[0]) ? $mWhere[0] : null;
                            }

                            //  Work out value
                            $mVal = isset($mWhere['value']) ? $mWhere['value'] : '[NAILS-VAL-NOT-FOUND]';

                            if ($mVal === '[NAILS-VAL-NOT-FOUND]') {
                                $mVal = isset($mWhere[1]) ? $mWhere[1] : null;
                            }

                            //  Escaped?
                            $bEscape = isset($mWhere['escape']) ? (bool) $mWhere['escape'] : '[NAILS-ESCAPE-NOT-FOUND]';

                            if ($bEscape === '[NAILS-ESCAPE-NOT-FOUND]') {
                                $bEscape = isset($mWhere[2]) ? $mWhere[2] : true;
                            }

                            //  If the $mColumn is an array then we should concat them together
                            if (is_array($mColumn)) {
                                $mColumn = 'CONCAT_WS(" ", ' . implode(',', $mColumn) . ')';
                            }

                            //  Test if there's an SQL operator
                            if (!(bool) preg_match('/(<|>|!|=|\sIS NULL|\sIS NOT NULL|\sEXISTS|\sBETWEEN|\sLIKE|\sIN\s*\(|\s)/i', trim($mColumn))) {
                                $sOperator = is_null($mVal) ? ' IS ' : '=';
                            } else {
                                $sOperator = '';
                            }

                            //  Got something?
                            if ($mColumn) {

                                switch ($sWhereType) {

                                    case 'where' :
                                    case 'or_where' :

                                        if ($bEscape) {
                                            $mVal = $oDb->escape($mVal);
                                        }

                                        $aWhereCompiled[$sWhereType][] = $mColumn . $sOperator . $mVal;
                                        break;

                                    case 'where_in' :
                                    case 'or_where_in' :

                                        if (!is_array($mVal)) {
                                            $mVal = (array) $mVal;
                                        }

                                        if (!empty($mVal)) {
                                            if ($bEscape) {
                                                foreach ($mVal as &$sValue) {
                                                    $sValue = $oDb->escape($sValue);
                                                }
                                            }

                                            $aWhereCompiled[$sWhereType][] = $mColumn . ' IN (' . implode(',', $mVal) . ')';
                                        }
                                        break;

                                    case 'where_not_in' :
                                    case 'or_where_not_in' :

                                        if (!is_array($mVal)) {
                                            $mVal = (array) $mVal;
                                        }

                                        if (!empty($mVal)) {
                                            if ($bEscape) {
                                                foreach ($mVal as &$sValue) {
                                                    $sValue = $oDb->escape($sValue);
                                                }
                                            }

                                            $aWhereCompiled[$sWhereType][] = $mColumn . ' NOT IN (' . implode(',', $mVal) . ')';
                                        }
                                        break;
                                }
                            }
                        }
                    }

                } elseif (is_string($aData[$sWhereType])) {

                    /**
                     * The value is a straight up string, assume this is a compiled
                     * where string,
                     */

                    $aWhereCompiled[$sWhereType][] = $aData[$sWhereType];
                }
            }
        }

        /**
         * Now we need to compile all the conditionals into one big super query.
         * $aWhereStr is an array of the compressed where strings... will make
         * sense shortly...
         */

        if (!empty($aWhereCompiled)) {

            $aWhereStr = [];

            foreach ($aWhereCompiled as $sWhereType => $sValue) {
                if (!empty($sValue)) {
                    $aWhereStr[] = '(' . implode(' ' . $aWheres[$sWhereType] . ' ', $sValue) . ')';
                }
            }

            //  And reduce $aWhereStr to an actual string, like the name suggests
            if (!empty($aWhereStr)) {
                $aWhereStr = implode(' AND ', $aWhereStr);
                $oDb->where($aWhereStr);
            }
        }
    }
429618
protected function getCountCommonEvent($aData = [])
    {
        if (!empty($aData['keywords'])) {
            if (empty($aData['or_like'])) {
                $aData['or_like'] = [];
            }

            $sToSlug = strtolower(str_replace(' ', '_', $aData['keywords']));

            $aData['or_like'][] = [
                'column' => $this->sTableAlias . '.type',
                'value'  => $sToSlug,
            ];
            $aData['or_like'][] = [
                'column' => 'ue.email',
                'value'  => $aData['keywords'],
            ];
        }

        //  Common joins
        $oDb = Factory::service('Database');
        $oDb->join(NAILS_DB_PREFIX . 'user u', $this->sTableAlias . '.created_by = u.id', 'LEFT');
        $oDb->join(NAILS_DB_PREFIX . 'user_email ue', 'ue.user_id = u.id AND ue.is_primary = 1', 'LEFT');

        $this->getCountCommon($aData);
    }
1020042
function(sEntitySetName, sKeys) {
					sKeys = decodeURIComponent(sKeys);
					var oFoundEntry;
					var oEntitySet = that._mEntitySets[sEntitySetName];
					var aKeys = oEntitySet.keys;
					// split keys
					var aRequestedKeys = sKeys.split(',');

					// check number of keys to be equal to the entity keys and validates keys type for quotations
					if (aRequestedKeys.length !== aKeys.length) {
						that._logAndThrowMockServerCustomError(400, that._oErrorMessages.INVALID_KEY_PREDICATE_QUANTITY);
					}
					that._isRequestedKeysValid(oEntitySet, aRequestedKeys);
					if (aRequestedKeys.length === 1 && !aRequestedKeys[0].split('=')[1]) {
						aRequestedKeys = [aKeys[0] + "=" + aRequestedKeys[0]];
					}
					jQuery.each(that._oMockdata[sEntitySetName], function(iIndex, oEntry) {
						// check each key for existence and value
						for (var i = 0; i < aRequestedKeys.length; i++) {
							var aKeyVal = aRequestedKeys[i].split('=');
							var sKey = that._trim(aKeyVal[0]);
							//key doesn't match, continue to next entry
							if (!aKeys || aKeys.indexOf(sKey) === -1) {
								return true; // = continue
							}

							var sNewValue = that._trim(aKeyVal[1]);
							var sOrigiValue = oEntry[sKey];

							switch (oEntitySet.keysType[sKey]) {
								case "Edm.String":
									sNewValue = sNewValue.replace(/^\'|\'$/g, '');
									break;
								case "Edm.Time":
								case "Edm.DateTime":
									sOrigiValue = that._getDateTime(sOrigiValue);
									break;
								case "Edm.Int16":
								case "Edm.Int32":
									//case "Edm.Int64": In ODataModel this type is represented as a string. (https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.odata.type.Int64.html)
								case "Edm.Decimal":
								case "Edm.Byte":
								case "Edm.Double":
								case "Edm.Single":
								case "Edm.SByte":
									if (!that._isValidNumber(sNewValue)) {
										//TODO check better handling
										return false; // = break
									}
									sNewValue = parseFloat(sNewValue);
									break;
								case "Edm.Guid":
									sNewValue = sNewValue.replace(/^guid\'|\'$/g, '');
									break;
								case "Edm.Boolean":
									if (["true", "false"].indexOf(sNewValue) === -1) {
										that._logAndThrowMockServerCustomError(400, that._oErrorMessages.INVALID_KEY_TYPE, sKey);
									}
									sNewValue = sNewValue === "true";
									break;
								case "Edm.Binary":
								case "Edm.DateTimeOffset":
								default:
									sNewValue = sNewValue;
							}

							//value doesn't match, continue to next entry
							if (sOrigiValue !== sNewValue) {
								return true; // = continue
							}
						}
						oFoundEntry = {
							index: iIndex,
							entry: oEntry
						};
						return false; // = break
					});
					return oFoundEntry;
				}
329060
protected function _findInArray( array $aData, $mKey, $sDefault = '' )
    {
        $sVal = $sDefault;

        if ( array_key_exists( $mKey, $aData ) and is_scalar( $aData[$mKey] ) ) {
            $sVal = trim( (string) $aData[$mKey] );
        }

        return $sVal;
    }
1240303
function (sDateString) {
			var iMillis = NativeDate_parse.apply(Date, arguments);
			if (sDateString && typeof sDateString === "string") {
				// if the year is gt/eq 2034 we need to increment the
				// date by one additional day since this is broken in
				// PhantomJS => this is a workaround for the upper BUG!
				var m = /^(\d{4})(?:-(\d+)?-(\d+))(?:[T ](\d+):(\d+)(?::(\d+)(?:\.(\d+))?)?)?(?:Z(-?\d*))?$/.exec(sDateString);
				if (m && parseInt(m[1]) >= 2034) {
					iMillis += 24 * 60 * 60 * 1000;
				}
			}
			return iMillis;
		}
437210
protected function getCountCommon(array $aData = [])
    {
        //  If there's a search term, then we better get %LIKING%
        if (!empty($aData['keywords'])) {

            if (empty($aData['or_like'])) {
                $aData['or_like'] = [];
            }

            $iKeywordAsId = (int) preg_replace('/[^0-9]/', '', $aData['keywords']);

            if ($iKeywordAsId) {
                $aData['or_like'][] = [
                    'column' => $this->getTableAlias() . '.id',
                    'value'  => $iKeywordAsId,
                ];
            }

            $aData['or_like'][] = [
                'column' => $this->getTableAlias() . '.label',
                'value'  => $aData['keywords'],
            ];
        }

        // --------------------------------------------------------------------------

        //  Let the parent method handle sorting, etc
        parent::getCountCommon($aData);
    }
982201
static function isValidISODateString( $sDate )
	{
		if ( ! CLib::IsExistingString( $sDate ) )
		{
			return false;
		}

		$nTime	= strtotime( $sDate );
		return ( false !== $nTime &&
			0 == strcasecmp( $sDate, date( "Y-m-d", $nTime ) ) );
	}
154157
public function getInt(string $key, int $defaultValue = 0): int
    {
        return intval($this->get($key, $defaultValue));
    }