uniform-team / Uniform-Validation-Language

A logic language to simplify and improve online form validation.
Apache License 2.0
1 stars 0 forks source link

DateTime Support #16

Open dgp1130 opened 8 years ago

dgp1130 commented 8 years ago

It would be very useful to have Uniform support dates and times properly, so it can check whether or not they satisfy certain conditions. We should have a way of comparing dates and times to determine (at least) which happens before another (ie. end date must come after start date), a way of determining if a date is in the future or past (ie. meeting date must be in the future, birthday must be in the past), and a way of finding a time difference between dates (ie. start and end must be at least 3 days apart). We should do something similar for time as well and allow a combination of date-time too. There should also be a way to write a date/time/timespan literal to compare against and a way of accessing individual fields in all three types. An example syntax is below.

@today: <date set by stdlib>
@now: <datetime set by stdlib>

$("#meetingDay") {
    valid: this > @now; // Meeting time is in the future
}

$("#meetingTime") {
    // Time literals look like THH:MM:ss(AM|PM)
    valid: this >= T9:00:00AM and this <= T5:00:00PM; // Meeting is between 9 and 5
}

$("#signUpDate") {
    // Sign up for a date between 4/22/2016 and 4/26/2016
    // Date literals look like DYYYY-MM-dd
    valid: this >= D2016-4-22 and this <= D2016-4-26;
}

$("#registerDateTime") {
    // DateTime literals combine date and time
    valid: this >= D2016-4-22T9:00:00AM; // Register any date and time after 4/22/16@9AM.
}

$("#birthday") {
    @age: @today - this;
    valid: @age.year >= 18; // Is 18 years old
}

$("#trainingDates") {
    @timespan: $("#endDate") - $("#startDate");
    valid: @timespan.days <= 3; // Start and end are within 3 days of each other
}