2017 © Pedro Peláez
 

yii2-extension yii2-datetime-compare

DateTime comparison validator

image

eanushan/yii2-datetime-compare

DateTime comparison validator

  • Sunday, September 27, 2015
  • by EAnushan
  • Repository
  • 2 Watchers
  • 2 Stars
  • 226 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

yii2-datetime-compare

Latest Stable Version Latest Unstable Version License Total Downloads Monthly Downloads Daily Downloads, (*1)

DateTime comparison validator for Yii Framework 2.0. Temporary solution until this enhancement is implemented., (*2)

[[Empathy\Validators\DateTimeCompareValidator|compare]]

[
    // validates if the value of "birthday" attribute equals to that of "birthday_repeat"
    ['birthday', DateTimeCompareValidator::className()],

    // validates if birthday is less than or equal to today
    ['birthday', DateTimeCompareValidator::className(), 'compareValue' => date('Y-m-d H:i:s'), 'operator' => '<='],

    // validates if birthday is less than driver's license expiry
    ['birthday', DateTimeCompareValidator::className(), 'compareAttribute' => 'driver_license_expiry', 'operator' => '<'],
]

This validator compares the specified input datetime with another one and make sure if their relationship is as specified by the operator property., (*3)

  • compareAttribute: the name of the attribute whose value should be compared with. When the validator is being used to validate an attribute, the default value of this property would be the name of the attribute suffixed with _repeat. For example, if the attribute being validated is birthday, then this property will default to birthday_repeat.
  • compareValue: a constant value that the input value should be compared with. When both of this property and compareAttribute are specified, this property will take precedence.
  • operator: the comparison operator. Defaults to ==, meaning checking if the input value is equal to that of compareAttribute or compareValue. The following operators are supported:
    • ==: check if two values are equal. The comparison is done is non-strict mode.
    • ===: check if two values are equal. The comparison is done is strict mode.
    • !=: check if two values are NOT equal. The comparison is done is non-strict mode.
    • !==: check if two values are NOT equal. The comparison is done is strict mode.
    • >: check if value being validated is greater than the value being compared with.
    • >=: check if value being validated is greater than or equal to the value being compared with.
    • <: check if value being validated is less than the value being compared with.
    • <=: check if value being validated is less than or equal to the value being compared with.
  • format: Date format to parse values with. If blank, PHP Date will try and guess your format.
  • jsFormat: Date format to parse values with client side. If blank, Moment.js will try and guess your format. Moment.js will not guess all formats correctly, and this feature will be deprecated in future releases of Moment.js. See https://github.com/moment/moment/issues/1407

Installation

The preferred way to install this extension is through composer., (*4)

Note: Check the composer.json for this extension's requirements and dependencies., (*5)

Run, (*6)

$ composer require empathy/yii2-datetime-compare

The Versions

27/09 2015

dev-master

9999999-dev https://github.com/empathy/yii2-datetime-compare

DateTime comparison validator

  Sources   Download

BSD 3-Clause

by Anushan Easwaramoorthy

plugin extension yii2 form widget datetime

26/02 2015

v1.0.0

1.0.0.0 https://github.com/EAnushan/yii2-datetime-compare

DateTime comparison validator

  Sources   Download

BSD 3-Clause

by Anushan Easwaramoorthy

plugin extension yii2 form widget datetime