Skip to content

Commit

Permalink
Add time and timezone validation rules. Fixed typos (#100)
Browse files Browse the repository at this point in the history
Introduced new schema rules for time, timezone, and timezone offset
validation. These enhancements boost data verification capabilities. It
ensures accuracy of time and timezone identifiers, including timezone
offsets. Relevant code and tests have also been added in the
'Rules/Cell' directory.
  • Loading branch information
SmetDenis authored Mar 26, 2024
1 parent b9c4aaa commit 397ad99
Show file tree
Hide file tree
Showing 62 changed files with 612 additions and 63 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![GitHub Release](https://img.shields.io/github/v/release/jbzoo/csv-blueprint?label=Latest)](https://github.com/jbzoo/csv-blueprint/releases) [![Total Downloads](https://poser.pugx.org/jbzoo/csv-blueprint/downloads)](https://packagist.org/packages/jbzoo/csv-blueprint/stats) [![Docker Pulls](https://img.shields.io/docker/pulls/jbzoo/csv-blueprint.svg)](https://hub.docker.com/r/jbzoo/csv-blueprint/tags) [![Docker Image Size](https://img.shields.io/docker/image-size/jbzoo/csv-blueprint)](https://hub.docker.com/r/jbzoo/csv-blueprint/tags)

<!-- rules-counter -->
[![Static Badge](https://img.shields.io/badge/Rules-278-green?label=Total%20number%20of%20rules&labelColor=darkgreen&color=gray)](schema-examples/full.yml) [![Static Badge](https://img.shields.io/badge/Rules-67-green?label=Cell%20rules&labelColor=blue&color=gray)](src/Rules/Cell) [![Static Badge](https://img.shields.io/badge/Rules-206-green?label=Aggregate%20rules&labelColor=blue&color=gray)](src/Rules/Aggregate) [![Static Badge](https://img.shields.io/badge/Rules-5-green?label=Extra%20checks&labelColor=blue&color=gray)](#extra-checks) [![Static Badge](https://img.shields.io/badge/Rules-211-green?label=Plan%20to%20add&labelColor=gray&color=gray)](tests/schemas/todo.yml)
[![Static Badge](https://img.shields.io/badge/Rules-282-green?label=Total%20number%20of%20rules&labelColor=darkgreen&color=gray)](schema-examples/full.yml) [![Static Badge](https://img.shields.io/badge/Rules-71-green?label=Cell%20rules&labelColor=blue&color=gray)](src/Rules/Cell) [![Static Badge](https://img.shields.io/badge/Rules-206-green?label=Aggregate%20rules&labelColor=blue&color=gray)](src/Rules/Aggregate) [![Static Badge](https://img.shields.io/badge/Rules-5-green?label=Extra%20checks&labelColor=blue&color=gray)](#extra-checks) [![Static Badge](https://img.shields.io/badge/Rules-207-green?label=Plan%20to%20add&labelColor=gray&color=gray)](tests/schemas/todo.yml)
<!-- /rules-counter -->

## Introduction
Expand Down Expand Up @@ -234,6 +234,10 @@ columns:
date_max: +1 day # Example of relative formats
date_format: Y-m-d # Check strict format of the date.
is_date: true # Accepts arbitrary date format. Is shows error if failed to convert to timestamp.
is_timezone: true # Allow only timezone identifiers. Case-insensitive. Example: "Europe/London", "utc".
is_timezone_offset: true # Allow only timezone offsets. Example: "+03:00".
is_time: true # Check if the cell value is a valid time in the format "HH:MM:SS AM/PM" / "HH:MM:SS" / "HH:MM". Case-insensitive.
is_leap_year: true # Check if the cell value is a leap year. Example: "2008", "2008-02-29 23:59:59 UTC".

# Specific formats
is_bool: true # Allow only boolean values "true" and "false", case-insensitive.
Expand Down
4 changes: 4 additions & 0 deletions schema-examples/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
"date_max" : "+1 day",
"date_format" : "Y-m-d",
"is_date" : true,
"is_timezone" : true,
"is_timezone_offset" : true,
"is_time" : true,
"is_leap_year" : true,

"is_bool" : true,
"is_ip4" : true,
Expand Down
22 changes: 13 additions & 9 deletions schema-examples/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,19 @@
'precision_less' => 8,
'precision_max' => 9,

'date_min' => '-100 years',
'date_greater' => '-99 days',
'date_not' => '2006-01-02 15:04:05 -0700 Europe/Rome',
'date' => '01 Jan 2000',
'date_less' => 'now',
'date_max' => '+1 day',
'date_format' => 'Y-m-d',

'is_date' => true,
'date_min' => '-100 years',
'date_greater' => '-99 days',
'date_not' => '2006-01-02 15:04:05 -0700 Europe/Rome',
'date' => '01 Jan 2000',
'date_less' => 'now',
'date_max' => '+1 day',
'date_format' => 'Y-m-d',
'is_date' => true,
'is_timezone' => true,
'is_timezone_offset' => true,
'is_time' => true,
'is_leap_year' => true,

'is_bool' => true,
'is_ip4' => true,
'is_url' => true,
Expand Down
4 changes: 4 additions & 0 deletions schema-examples/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ columns:
date_max: +1 day # Example of relative formats
date_format: Y-m-d # Check strict format of the date.
is_date: true # Accepts arbitrary date format. Is shows error if failed to convert to timestamp.
is_timezone: true # Allow only timezone identifiers. Case-insensitive. Example: "Europe/London", "utc".
is_timezone_offset: true # Allow only timezone offsets. Example: "+03:00".
is_time: true # Check if the cell value is a valid time in the format "HH:MM:SS AM/PM" / "HH:MM:SS" / "HH:MM". Case-insensitive.
is_leap_year: true # Check if the cell value is a leap year. Example: "2008", "2008-02-29 23:59:59 UTC".

# Specific formats
is_bool: true # Allow only boolean values "true" and "false", case-insensitive.
Expand Down
4 changes: 4 additions & 0 deletions schema-examples/full_clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ columns:
date_max: '+1 day'
date_format: Y-m-d
is_date: true
is_timezone: true
is_timezone_offset: true
is_time: true
is_leap_year: true

is_bool: true
is_ip4: true
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/AbstarctRuleCombo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace JBZoo\CsvBlueprint\Rules;

use JBZoo\CsvBlueprint\Rules\Aggregate\AbstarctAggregateRuleCombo;
use JBZoo\CsvBlueprint\Rules\Aggregate\AbstractAggregateRuleCombo;
use JBZoo\CsvBlueprint\Rules\Cell\AbstractCellRuleCombo;
use JBZoo\CsvBlueprint\Validators\Error;
use JBZoo\CsvBlueprint\Validators\ValidatorColumn;
Expand Down Expand Up @@ -106,7 +106,7 @@ private function validateCombo(array|string $cellValue): ?string
return $this->validateComboCell($cellValue, $this->mode);
}

if ($this instanceof AbstarctAggregateRuleCombo) {
if ($this instanceof AbstractAggregateRuleCombo) {
if (!\is_array($cellValue)) {
throw new \InvalidArgumentException('The value should be an array of numbers/strings');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

abstract class AbstarctAggregateRule extends AbstarctRule
abstract class AbstractAggregateRule extends AbstarctRule
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_STRINGS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use JBZoo\CsvBlueprint\Rules\AbstarctRuleCombo;

abstract class AbstarctAggregateRuleCombo extends AbstarctRuleCombo
abstract class AbstractAggregateRuleCombo extends AbstarctRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_STRINGS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboAverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Average;

final class ComboAverage extends AbstarctAggregateRuleCombo
final class ComboAverage extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCoefOfVar.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Descriptive;

final class ComboCoefOfVar extends AbstarctAggregateRuleCombo
final class ComboCoefOfVar extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboContraharmonicMean.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Average;

final class ComboContraharmonicMean extends AbstarctAggregateRuleCombo
final class ComboContraharmonicMean extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

final class ComboCount extends AbstarctAggregateRuleCombo
final class ComboCount extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_BOOL;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCountDistinct.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

final class ComboCountDistinct extends AbstarctAggregateRuleCombo
final class ComboCountDistinct extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_STRINGS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCountEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

final class ComboCountEmpty extends AbstarctAggregateRuleCombo
final class ComboCountEmpty extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_STRINGS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCountEven.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

final class ComboCountEven extends AbstarctAggregateRuleCombo
final class ComboCountEven extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_INTS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCountNegative.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

final class ComboCountNegative extends AbstarctAggregateRuleCombo
final class ComboCountNegative extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_INTS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCountNotEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

final class ComboCountNotEmpty extends AbstarctAggregateRuleCombo
final class ComboCountNotEmpty extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_STRINGS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCountOdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

final class ComboCountOdd extends AbstarctAggregateRuleCombo
final class ComboCountOdd extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_INTS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCountPositive.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

final class ComboCountPositive extends AbstarctAggregateRuleCombo
final class ComboCountPositive extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_INTS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCountPrime.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use Respect\Validation\Validator;

final class ComboCountPrime extends AbstarctAggregateRuleCombo
final class ComboCountPrime extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_INTS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCountZero.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

final class ComboCountZero extends AbstarctAggregateRuleCombo
final class ComboCountZero extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_INTS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboCubicMean.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Average;

final class ComboCubicMean extends AbstarctAggregateRuleCombo
final class ComboCubicMean extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboFirstNum.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

final class ComboFirstNum extends AbstarctAggregateRuleCombo
final class ComboFirstNum extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboGeometricMean.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Average;

final class ComboGeometricMean extends AbstarctAggregateRuleCombo
final class ComboGeometricMean extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboHarmonicMean.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Average;

final class ComboHarmonicMean extends AbstarctAggregateRuleCombo
final class ComboHarmonicMean extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboInterquartileMean.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Average;

final class ComboInterquartileMean extends AbstarctAggregateRuleCombo
final class ComboInterquartileMean extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboLastNum.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use JBZoo\CsvBlueprint\Rules\AbstarctRule;

final class ComboLastNum extends AbstarctAggregateRuleCombo
final class ComboLastNum extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboMeanAbsDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Descriptive;

final class ComboMeanAbsDev extends AbstarctAggregateRuleCombo
final class ComboMeanAbsDev extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboMedian.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Average;

final class ComboMedian extends AbstarctAggregateRuleCombo
final class ComboMedian extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboMedianAbsDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Descriptive;

final class ComboMedianAbsDev extends AbstarctAggregateRuleCombo
final class ComboMedianAbsDev extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboMidhinge.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Descriptive;

final class ComboMidhinge extends AbstarctAggregateRuleCombo
final class ComboMidhinge extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboNthNum.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use function JBZoo\Utils\float;

final class ComboNthNum extends AbstarctAggregateRuleCombo
final class ComboNthNum extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboPercentile.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use function JBZoo\Utils\float;

final class ComboPercentile extends AbstarctAggregateRuleCombo
final class ComboPercentile extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboPopulationVariance.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Descriptive;

final class ComboPopulationVariance extends AbstarctAggregateRuleCombo
final class ComboPopulationVariance extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboQuartiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use function JBZoo\Utils\float;

final class ComboQuartiles extends AbstarctAggregateRuleCombo
final class ComboQuartiles extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboRootMeanSquare.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Average;

final class ComboRootMeanSquare extends AbstarctAggregateRuleCombo
final class ComboRootMeanSquare extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboSampleVariance.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Descriptive;

final class ComboSampleVariance extends AbstarctAggregateRuleCombo
final class ComboSampleVariance extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboStddev.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Descriptive;

final class ComboStddev extends AbstarctAggregateRuleCombo
final class ComboStddev extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Aggregate/ComboStddevPop.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use JBZoo\CsvBlueprint\Rules\AbstarctRule;
use MathPHP\Statistics\Descriptive;

final class ComboStddevPop extends AbstarctAggregateRuleCombo
final class ComboStddevPop extends AbstractAggregateRuleCombo
{
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS;

Expand Down
Loading

0 comments on commit 397ad99

Please sign in to comment.