module DateColumnAudit

Overview

Inspect ONE column of a CSV and sort every value into a date shape class. Shape only: it cannot tell whether an ambiguous value is day first or month first, and it does not read time zones. The clock is never read.

Defined in:

date_column_audit.cr

Constant Summary

AMBIGUOUS = "ambiguous day/month"
CLASSES = [ISO_DATE, ISO_IMPOSSIBLE, ISO_TIME, DAY_FIRST, MONTH_FIRST, AMBIGUOUS, IMPOSSIBLE_SLASH, OTHER]
DAY_FIRST = "day first"
IMPOSSIBLE_SLASH = "impossible day/month"
ISO_DATE = "yyyy-mm-dd"
ISO_IMPOSSIBLE = "yyyy-mm-dd impossible"
ISO_RE = /\A([0-9]{4})-([0-9]{2})-([0-9]{2})\z/
ISO_TIME = "yyyy-mm-dd HH:mm[:ss]"
MIXABLE = [ISO_DATE, ISO_TIME, DAY_FIRST, MONTH_FIRST]
MONTH_FIRST = "month first"
OTHER = "other text"
SLASH_RE = /\A([0-9]{1,2})([\/.\-])([0-9]{1,2})\2([0-9]{4})\z/
TIME_RE = /\A([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2})(?::([0-9]{2}))?\z/
USAGE = "usage: date-column-audit file.csv --column NAME\nShape check of one column: it cannot tell whether an ambiguous value is day first or month first, and it does not read time zones. More: https://www.onegtmlab.dev/tool-directory/verification/zerobounce"
VERSION = "1.0.0"

Class Method Summary

Class Method Detail

def self.audit(text : String, column : String) : Report #

Reads the CSV text and audits the column named by column.


[View source]
def self.classify(value : String) : String #

One trimmed, non-empty value gets exactly one class.


[View source]
def self.cli(args : Array(String), stdout : IO, stderr : IO) : Int32 #

Exit codes: 0 no problems, 1 problems found, 2 unreadable file, unknown column, missing --column, unknown option or empty input.


[View source]
def self.days_in_month(y : Int32, m : Int32) : Int32 #

[View source]
def self.leap?(y : Int32) : Bool #

[View source]
def self.parse_csv(text : String) : Array(Array(String)) #

Small CSV reader: comma separated, double quoted fields may hold commas, line breaks and "" for a quote mark. Returns rows of raw cell strings.


[View source]
def self.pct(count : Int32, whole : Int32) : String #

[View source]
def self.real_date?(y : Int32, m : Int32, d : Int32) : Bool #

[View source]
def self.real_time?(h : Int32, mi : Int32, s : Int32) : Bool #

[View source]
def self.render(r : Report) : String #

[View source]
def self.table(rows : Array(Array(String))) : String #

[View source]