Class humhub\libs\DbDateValidator

Inheritancehumhub\libs\DbDateValidator » yii\validators\DateValidator

Validates (user date format or database format) and converts it to an database date(-time) field

See also \yii\validators\DateValidator.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$convertToFormat string The format the value should converted to (database datetime or date format) humhub\libs\DbDateValidator
$targetAttribute string Attribute name to save converted value to humhub\libs\DbDateValidator
$timeAttribute string Attribute which holds the time in format hh::mm humhub\libs\DbDateValidator

Public Methods

Hide inherited methods

MethodDescriptionDefined By
init() humhub\libs\DbDateValidator
parseDateTime() Parses a date and optionally a time if timeAttribute is specified. humhub\libs\DbDateValidator
validateAttribute() humhub\libs\DbDateValidator

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
fixTimestampTimeZone() Converts the given timestamp from user (or configured) timezone to a utc timestamp humhub\libs\DbDateValidator
getTimeValue() Returns time value if provided by the model humhub\libs\DbDateValidator
hasTime() Checks a time attribute name is given, if empty don't handle time humhub\libs\DbDateValidator
parseDateTimeValue() Parses a date and a time value if timeAttribute is specified. humhub\libs\DbDateValidator
parseTimeValue() Parses given time value (hh:mm) to seconds humhub\libs\DbDateValidator

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
REGEX_DBFORMAT_DATE '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/' Database Field - Validators humhub\libs\DbDateValidator
REGEX_DBFORMAT_DATETIME '/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/' humhub\libs\DbDateValidator

Property Details

$convertToFormat public property

The format the value should converted to (database datetime or date format)

public string $convertToFormat 'Y-m-d H:i:s'
$targetAttribute public property

Attribute name to save converted value to

public string $targetAttribute null
$timeAttribute public property

Attribute which holds the time in format hh::mm

public string $timeAttribute ''

Method Details

fixTimestampTimeZone() protected method

Converts the given timestamp from user (or configured) timezone to a utc timestamp

protected integer fixTimestampTimeZone ( $ts, $timeZone )
$ts integer

The timestamp

$timeZone String

Users timezone

throws Exception
getTimeValue() protected method

Returns time value if provided by the model

protected string|null getTimeValue ( $model )
$model
return string|null

Time value (e.g. 12:00)

hasTime() protected method

Checks a time attribute name is given, if empty don't handle time

protected boolean hasTime ( )
init() public method

public void init ( )
parseDateTime() public static method

Parses a date and optionally a time if timeAttribute is specified.

public static integer parseDateTime ( $value, $timeValue null )
$value string
$timeValue
return integer

Timestamp in utc

throws Exception
parseDateTimeValue() protected method

Parses a date and a time value if timeAttribute is specified.

protected integer parseDateTimeValue ( $value, $timeValue null )
$value string
$timeValue
return integer

Timestamp in utc

throws Exception
parseTimeValue() protected method

Parses given time value (hh:mm) to seconds

protected integer parseTimeValue ( $value )
$value string
return integer

Time converted to seconds

validateAttribute() public method

public void validateAttribute ( $model, $attribute )
$model
$attribute