Module: AdiwgDateTimeFun

Defined in:
lib/adiwg/mdtranslator/internal/module_dateTimeFun.rb

Class Method Summary collapse

Class Method Details

.dateTimeFromString(inDateTime) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/adiwg/mdtranslator/internal/module_dateTimeFun.rb', line 12

def self.dateTimeFromString(inDateTime)
  hFormats = {'YMDhmsLZ'=> '%Y-%m-%dT%H:%M:%S.%L%z',
        'YMDhmsL'=> '%Y-%m-%dT%H:%M:%S.%L',
        'YMDhmsZ'=> '%Y-%m-%dT%H:%M:%S%z',
        'YMDhms'=> '%Y-%m-%dT%H:%M:%S',
        'YMDhmZ'=> '%Y-%m-%dT%H:%M%z',
        'YMDhm'=> '%Y-%m-%dT%H:%M',
        'YMDhZ'=> '%Y-%m-%dT%H%z',
        'YMDh'=> '%Y-%m-%dT%H',
        'YMD'=> '%Y-%m-%d',
        'YM'=> '%Y-%m',
        'Y'=> '%Y'}
  hFormats.each do |dateResolution, format|
    myDateTime = DateTime.strptime(inDateTime,format) rescue false
    return myDateTime, dateResolution if myDateTime
  end

  return nil, 'ERROR'
end

.stringDateFromDateTime(myDateTime, dateResolution) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/adiwg/mdtranslator/internal/module_dateTimeFun.rb', line 32

def self.stringDateFromDateTime(myDateTime,dateResolution)
  s = case dateResolution
      when 'YMDhmsLZ','YMDhmsL','YMDhmsZ', 'YMDhms',
        'YMDhmZ', 'YMDhm', 'YMDhZ', 'YMDh','YMD'
        myDateTime.strftime('%Y-%m-%d')
      when 'YM'
        myDateTime.strftime('%Y-%m')
      when 'Y'
        myDateTime.strftime('%Y')
      else
        'ERROR'
    end

  return s
end

.stringDateTimeFromDateTime(myDateTime, dateResolution) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/adiwg/mdtranslator/internal/module_dateTimeFun.rb', line 48

def self.stringDateTimeFromDateTime(myDateTime,dateResolution)
  s = case dateResolution
      when 'YMDhmsLZ'
        myDateTime.strftime('%Y-%m-%dT%H:%M:%S.%L%:z')
      when 'YMDhmsL'
        myDateTime.strftime('%Y-%m-%dT%H:%M:%S.%L')
      when 'YMDhmsZ'
        myDateTime.strftime('%Y-%m-%dT%H:%M:%S%:z')
      when 'YMDhms', 'YMD', 'YM', 'Y'
        myDateTime.strftime('%Y-%m-%dT%H:%M:%S')
      when 'YMDhmZ'
        myDateTime.strftime('%Y-%m-%dT%H:%M%:z')
      when 'YMDhm'
        myDateTime.strftime('%Y-%m-%dT%H:%M')
      when 'YMDhZ'
        myDateTime.strftime('%Y-%m-%dT%H%:z')
      when 'YMDh'
        myDateTime.strftime('%Y-%m-%dT%H')
      else
        'ERROR'
    end

  return s
end

.stringTimeFromDateTime(myDateTime, dateResolution) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/adiwg/mdtranslator/internal/module_dateTimeFun.rb', line 73

def self.stringTimeFromDateTime(myDateTime,dateResolution)
  s = case dateResolution
      when 'YMDhmsLZ'
        myDateTime.strftime('%H:%M:%S.%L%:z')
      when 'YMDhmsL'
        myDateTime.strftime('%H:%M:%S.%L')
      when 'YMDhmsZ'
        myDateTime.strftime('%H:%M:%S%:z')
      when 'YMDhms'
        myDateTime.strftime('%H:%M:%S')
      when 'YMDhmZ'
        myDateTime.strftime('%H:%M%:z')
      when 'YMDhm'
        myDateTime.strftime('%H:%M')
      when 'YMDhZ'
        myDateTime.strftime('%H%:z')
      when 'YMDh'
        myDateTime.strftime('%H')
      else
        'ERROR'
    end

  return s
end