ElxValidation.DateTime (elx_validation v0.1.3)
date
- The field under validation must be a valid, non-relative date.
- "2020-06-26"
time
- The field under validation must be a valid, non-relative time.
- am / pm is optional
- "20:13"
- "01:02"
- "02:40am"
- "05:20pm"
datetime
- The field under validation must be a valid datetime identifier
- "2020-06-26 12:20"
timezone
- The field under validation must be a valid timezone identifier
- "+04:30"
- "-01:30"
data = %{
birthdate: "1990-04-17",
start_time: "13:30",
expired: "2020-06-28 12:20",
my_zone: "+04:30"
}
rules = [
%{
field: "birthdate",
validate: ["date"]
},
%{
field: "start_time",
validate: ["time"]
},
%{
field: "expired",
validate: ["datetime"]
},
%{
field: "my_zone",
validate: ["timezone"]
},
]
date_equals:date
- The field under validation must be equal to the given date.
after:date
- The field under validation must be a value after a given date.
after_or_equal:date
- The field under validation must be a value after or equal to the given date. For more information, see the after rule.
before:date
- The field under validation must be a value preceding the given date.
before_or_equal:date
- The field under validation must be a value preceding or equal to the given date.
data = %{ eq_bd: "1990-04-17", ---> == "1990-04-17" after_bd: "1990-04-20", ---> > "1990-04-17" after_equal_bd: "1990-04-18", ---> >= "1990-04-17" before_bd: "1990-04-16", ---> < "1990-04-17" before_equal_bd: "1990-04-17", ---> <= "1990-04-17" } rules = [ %{ field: "eq_bd", validate: ["date_equals:1990-04-17"] }, %{ field: "after_bd", validate: ["after:1990-04-17"] }, %{ field: "after_equal_bd", validate: ["after_or_equal:1990-04-17"] }, %{ field: "before_bd", validate: ["before:1990-04-17"] }, %{ field: "before_equal_bd", validate: ["before_or_equal:1990-04-17"] } ]
Link to this section Summary
Functions
check target and value is date and equal
check target and value is date and target after value
check target and value is date and target after or equal value
check target and value is date and target before value
check target and value is date and target before or equal value
check target is Date
check target is DateTime
check target is Time
check target is Timezone data
Link to this section Functions
date_equals(target, value)
check target and value is date and equal
is_after(target, value)
check target and value is date and target after value
is_after_or_equal(target, value)
check target and value is date and target after or equal value
is_before(target, value)
check target and value is date and target before value
is_before_or_equal(target, value)
check target and value is date and target before or equal value
is_date(target)
check target is Date
is_date_time(target)
check target is DateTime
- YYYY-MM-DD HH:MM:SS -> passed
is_time(target)
check target is Time
- 01:12am -> passed
- 04:30pm -> passed
- 13:12 -> passed
- am /pm -> optional
is_timezone(target)
check target is Timezone data
- +04:30 -> passed
- -01:15 -> passed