Class: RBEDI::EDIDateTime
- Inherits:
-
Object
- Object
- RBEDI::EDIDateTime
- Defined in:
- lib/rbedi/edi_date_time.rb
Constant Summary collapse
- CCYYMMDD_STRFTIME =
"%Y%m%d"
- YYMMDD_STRFTIME =
"%y%m%d"
- HHMMSS_STRFTIME =
"%H%M%S"
- HHMM_STRFTIME =
"%H%M"
- DEFAULT_OFFSET =
DateTime.now.strftime("%z")
Instance Attribute Summary collapse
-
#datetime_end ⇒ Object
Returns the value of attribute datetime_end.
-
#datetime_start ⇒ Object
Returns the value of attribute datetime_start.
Class Method Summary collapse
Instance Method Summary collapse
- #ccyymmdd ⇒ Object
- #hhmm ⇒ Object
- #hhmmss ⇒ Object
-
#initialize(datetime_start, datetime_end = nil) ⇒ EDIDateTime
constructor
A new instance of EDIDateTime.
- #yymmdd ⇒ Object
Constructor Details
#initialize(datetime_start, datetime_end = nil) ⇒ EDIDateTime
Returns a new instance of EDIDateTime.
9 10 11 12 13 14 15 16 17 |
# File 'lib/rbedi/edi_date_time.rb', line 9 def initialize(datetime_start, datetime_end = nil) if datetime_start.is_a?(EDIDateTime) @datetime_start = datetime_start.datetime_start @datetime_end = datetime_start.datetime_end else @datetime_start = datetime_start @datetime_end = datetime_end end end |
Instance Attribute Details
#datetime_end ⇒ Object
Returns the value of attribute datetime_end.
67 68 69 |
# File 'lib/rbedi/edi_date_time.rb', line 67 def datetime_end @datetime_end end |
#datetime_start ⇒ Object
Returns the value of attribute datetime_start.
67 68 69 |
# File 'lib/rbedi/edi_date_time.rb', line 67 def datetime_start @datetime_start end |
Class Method Details
.now ⇒ Object
19 20 21 |
# File 'lib/rbedi/edi_date_time.rb', line 19 def self.now new(DateTime.now) end |
.now_range ⇒ Object
23 24 25 |
# File 'lib/rbedi/edi_date_time.rb', line 23 def self.now_range new(DateTime.now, DateTime.now) end |
.parse(date: "", time: "", offset: DEFAULT_OFFSET) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rbedi/edi_date_time.rb', line 27 def self.parse(date: "", time: "", offset: DEFAULT_OFFSET) start_date, end_date = date.split("-") start_time, end_time = time.split("-") if start_date.nil? || start_date.empty? date_strftime = "" else date_strftime = CCYYMMDD_STRFTIME if start_date.length == 8 date_strftime = YYMMDD_STRFTIME if start_date.length == 6 end if start_time.nil? || start_time.empty? time_strftime = "" else time_strftime = HHMMSS_STRFTIME if start_time.length == 6 time_strftime = HHMM_STRFTIME if start_time.length == 4 end start_datetime = DateTime.strptime("#{start_date}#{start_time}#{offset}", date_strftime + time_strftime + "%z") end_datetime = end_date || end_time ? DateTime.strptime("#{end_date}#{end_time}#{offset}", date_strftime + time_strftime + "%z") : nil new(start_datetime, end_datetime) end |
Instance Method Details
#ccyymmdd ⇒ Object
51 52 53 |
# File 'lib/rbedi/edi_date_time.rb', line 51 def ccyymmdd @datetime_end ? "#{@datetime_start.strftime(CCYYMMDD_STRFTIME)}-#{@datetime_end.strftime(CCYYMMDD_STRFTIME)}" : @datetime_start.strftime(CCYYMMDD_STRFTIME) end |
#hhmm ⇒ Object
63 64 65 |
# File 'lib/rbedi/edi_date_time.rb', line 63 def hhmm @datetime_end ? "#{@datetime_start.strftime(HHMM_STRFTIME)}-#{@datetime_end.strftime(HHMM_STRFTIME)}" : @datetime_start.strftime(HHMM_STRFTIME) end |
#hhmmss ⇒ Object
59 60 61 |
# File 'lib/rbedi/edi_date_time.rb', line 59 def hhmmss @datetime_end ? "#{@datetime_start.strftime(HHMMSS_STRFTIME)}-#{@datetime_end.strftime(HHMMSS_STRFTIME)}" : @datetime_start.strftime(HHMMSS_STRFTIME) end |
#yymmdd ⇒ Object
55 56 57 |
# File 'lib/rbedi/edi_date_time.rb', line 55 def yymmdd @datetime_end ? "#{@datetime_start.strftime(YYMMDD_STRFTIME)}-#{@datetime_end.strftime(YYMMDD_STRFTIME)}" : @datetime_start.strftime(YYMMDD_STRFTIME) end |