module DateFormats

todo/fix: make logging class configurable - lets you use logutils etc.

Constants

DAY_DE
DAY_EN
DAY_ES
DAY_FR
DAY_IT
DAY_NAMES
DAY_PT
DB__DATE_RE

e.g. 2012-09-14 => YYYY-MM-DD

note: allow 2012-9-3 e.g. no leading zero required

regex_db2

DB__DATE_TIME_RE

todo/fix: add rule with allowed / separator (e.g. 2019/12/11)

BUT must be used in all following case too (NO mix'n'match allowed e.g. 2019-11/12)
DD_MM_YYYY__DATE_RE

e.g. 14.09.2012 => DD.MM.YYYY regex_de3

DD_MM_YYYY__DATE_TIME_RE

e.g. 14.09.2012 20:30 => DD.MM.YYYY HH:MM

note: allow 2.3.2012 e.g. no leading zero required
note: allow hour as 20.30

regex_de

DD_MM__DATE_RE

e.g. 14.09. => DD.MM. w/ implied year

note: allow end delimiter ] e.g. [Sa 12.01.] or end-of-string ($) too
note: we use a lookahead for last part e.g. (?:\s+|$|[\]]) - do NOT cosume

regex_de4 (use lookahead assert)

DD_MM__DATE_TIME_RE

e.g. 14.09. 20:30 => DD.MM. HH:MM

note: allow 2.3.2012 e.g. no leading zero required
note: allow hour as 20.30  or 3.30 instead of 03.30

regex_de2

DE__DAY_MM_DD__DATE_RE

e.g. Fr. 26.7. or Sa. 27.7.

or  Fr 26.7.  or  Sa 27.7.
or  Fr, 26.7. or  Sa, 27.7.
DE__DAY_MM_DD__DATE_TIME_RE

e.g. Sa., 16.5., 18.00 Uhr or Mo., 18.5., 20.30 Uhr

Sa 16.5. 18.00         or  Mo 18.5. 20.30
EN__DAY_MONTH_DD__DATE_RE

e.g. Fri Aug/9 or Fri Aug 9

Fri, Aug/9 or Fri, Aug 9
EN__DAY_MONTH_DD__DATE_TIME_RE

e.g. Fri Aug/9 18:00 or Fri Aug 9 18:00

Fri, Aug/9 18:00 or Fri, Aug 9 18:00
EN__DD_MONTH_YYYY__DATE_TIME_RE

e.g. 12 May 2013 14:00 => D|DD.MMM.YYYY H|HH:MM

or 12 May 2013 14h00
EN__DD_MONTH__DATE_RE

e.g. 12 May => D|DD.MMM w/ implied year

EN__MONTH_DD_YYYY__DATE_RE

e.g. Jun/12 2013

or Jun 12 2013
or Jun 12, 2013
EN__MONTH_DD_YYYY__DATE_TIME_RE

e.g. Jun/12 2011 14:00 or

Jun 12, 2011 14:00 or
Jun 12, 2011 14h00
EN__MONTH_DD__DATE_RE

check if [/ ] works!!!! in x mode ??

EN__MONTH_DD__DATE_TIME_RE

e.g. Jun/12 14:00 w/ implied year H|HH:MM

or  Jun 12 14h00
ES__DAY_DD_MM__DATE_RE

e.g. Vie. 16.8. or Sáb. 17.8.

or  Vie 16.8.  or  Sáb 17.8.
ES__DAY_DD_MONTH__DATE_RE

e.g. Vie 12 Ene w/ implied year

ES__DAY_DD_MONTH__DATE_TIME_RE

e.g. Sáb 5 Ene 19:30

ES__DD_MONTH__DATE_RE

e.g. 12 Ene w/ implied year

FORMATS
FORMATS_BASE

map tables - 1) regex, 2) tag - note: order matters; first come-first matched/served

FORMATS_DE
FORMATS_EN
FORMATS_ES
FORMATS_FR
FORMATS_IT
FORMATS_PT
FR__DAY_DD_MONTH__DATE_RE

e.g. Ven 8 Août or [Ven 8 Août] or Ven 8. Août or [Ven 8. Août]

note: do NOT consume [] in regex (use lookahead assert)
IT__DAY_MM_DD__DATE_RE

e.g. Sab. 24.8. or Dom. 25.8.

or  Sab 24.8.  or Dom 25.8.
MAJOR
MINOR
MONTH_DE
MONTH_EN

helpers for building format regex patterns

MONTH_ES
MONTH_FR
MONTH_IT
MONTH_NAMES

note: always sort lines with longest words, abbrevations first!!!! todo/fix: add/split into MONTH_NAMES and MONTH_ABBREVS (and DAY_NAMES and DAY_ABBREVS) - why? why not?

MONTH_PT
PATCH
PT__DAY_DD_MM__DATE_RE

e.g. Sáb, 29/07 or Seg, 31/07

Sáb 29/07  or  Seg 31/07
PT__DAY_DD_MONTH__DATE_RE

e.g. Sáb, 13/Maio or Qui, 08/Junho

or  Sáb 13 Maio or Qui 8 Junho
PT__DD_MM_YYYY_DAY__DATE_RE

e.g. 29/03/2003 - Sábado or

29/3/2003 Sábado
VERSION

Public Class Methods

banner() click to toggle source
build_names( lines ) click to toggle source
# File lib/date-formats/reader.rb, line 60
def self.build_names( lines )
  ## join all words together into a single string e.g.
  ##   January|Jan|February|Feb|March|Mar|April|Apr|May|June|Jun|...
  lines.map { |line| line.join('|') }.join('|')
end
find!( line, lang: DateFormats.lang, start: Date.new( Date.today.year, 1, 1 ) ) click to toggle source
# File lib/date-formats/parser.rb, line 31
def self.find!( line,
                lang:  DateFormats.lang,    ## todo/check: is there a "generic" like self.class.lang form?
                start: Date.new( Date.today.year, 1, 1 ) ## note: default to current YYYY.01.01. if no start provided
              )
  parser( lang: lang ).find!( line, start: start )
end
lang() click to toggle source
# File lib/date-formats/parser.rb, line 7
def self.lang
  @@lang ||= :en            ## defaults to english (:en)
end
lang=( value ) click to toggle source
# File lib/date-formats/parser.rb, line 10
def self.lang=( value )
  @@lang = value.to_sym    ## note: make sure lang is always a symbol for now (NOT a string)
  @@lang      ## todo/check: remove  =() method always returns passed in value? double check
end
parse( line, lang: DateFormats.lang, start: Date.new( Date.today.year, 1, 1 ) ) click to toggle source
# File lib/date-formats/parser.rb, line 24
def self.parse( line,
                lang:    DateFormats.lang,    ## todo/check: is there a "generic" like self.class.lang form? yes, module DateFormats needs to get changed to class DateFormats to work!!
                start:   Date.new( Date.today.year, 1, 1 )  ## note: default to current YYYY.01.01. if no start provided
              )
  parser( lang: lang ).parse( line, start: start )
end
parse_day( txt ) click to toggle source
# File lib/date-formats/reader.rb, line 50
def self.parse_day( txt )
    lines = Reader.parse( txt )
    if lines.size != 7
      puts "*** !!! ERROR !!! reading day names; got #{lines.size} lines - expected 7"
      exit 1
    end
    lines
end
parse_month( txt ) click to toggle source
# File lib/date-formats/reader.rb, line 41
def self.parse_month( txt )
    lines = Reader.parse( txt )
    if lines.size != 12
      puts "*** !!! ERROR !!! reading month names; got #{lines.size} lines - expected 12"
      exit 1
    end
    lines
end
parser( lang: ) click to toggle source
# File lib/date-formats/parser.rb, line 16
def self.parser( lang: )  ## find parser
  lang = lang.to_sym  ## note: make sure lang is always a symbol for now (NOT a string)

  ## note: cache all "built-in" lang versions (e.g. formats == nil)
  @@parser ||= {}
  @@parser[ lang ] ||= DateParser.new( lang: lang )
end
root() click to toggle source
# File lib/date-formats/version.rb, line 18
def self.root
  File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
end
version() click to toggle source
# File lib/date-formats/version.rb, line 10
def self.version
  VERSION
end