Class humhub\libs\DbDateValidator
Inheritance | humhub\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
Property | Type | Description | Defined 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
Method | Description | Defined 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
Method | Description | Defined 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
Constant | Value | Description | Defined 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
The format the value should converted to (database datetime or date format)
Attribute name to save converted value to
Attribute which holds the time in format hh::mm
Method Details
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 |
---|
Returns time value if provided by the model
protected string|null getTimeValue ( $model ) | ||
$model | ||
return | string|null | Time value (e.g. 12:00) |
---|
Checks a time attribute name is given, if empty don't handle time
protected boolean hasTime ( ) |
public void init ( ) |
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 |
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 |
Parses given time value (hh:mm) to seconds
protected integer parseTimeValue ( $value ) | ||
$value | string | |
return | integer | Time converted to seconds |
---|
public void validateAttribute ( $model, $attribute ) | ||
$model | ||
$attribute |