luckyframework / luckyframework/avram

Add `validate_between` for numbers and Time

Open
#1,146 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

This would allow you to validate that either a number or a Time based column sits between some lower bounds and some upper bounds.

Something like this

```crystal
validate_between age, min: 30, max: 60
validate_between coupon, min: 2.days.ago, max: 2.days.from_now
```

We actually already have `validate_numeric` for validating that a number is within some range, so we could just make this for `Time` only, but I figure someone might reach for a number and wonder why it didn't work... We wouldn't get rid of `validate_numeric` though because with that you can set only a min or only a max and not care about the other bounds. With this you want to ensure that it's directly between the two.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing validate_numeric implementation and read how validation bounds are represented and tested. Define the validate_between behavior for numeric and Time columns, including both required lower and upper bounds, and verify the example calls reject values outside the interval.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.