module OrcidClient::Date
Public Instance Methods
get_date_parts(iso8601_time)
click to toggle source
# File lib/orcid_client/date.rb, line 3 def get_date_parts(iso8601_time) return { "date_parts" => [[]] } if iso8601_time.nil? year = iso8601_time[0..3].to_i month = iso8601_time[5..6].to_i day = iso8601_time[8..9].to_i { 'date-parts' => [[year, month, day].reject { |part| part == 0 }] } end
get_date_parts_from_parts(year = nil, month = nil, day = nil)
click to toggle source
# File lib/orcid_client/date.rb, line 21 def get_date_parts_from_parts(year = nil, month = nil, day = nil) { 'date-parts' => [[year.to_i, month.to_i, day.to_i].reject { |part| part == 0 }] } end
get_iso8601_from_epoch(epoch)
click to toggle source
# File lib/orcid_client/date.rb, line 52 def get_iso8601_from_epoch(epoch) return nil if epoch.blank? # handle milliseconds epoch = epoch.to_i epoch = epoch / 1000 if epoch > 9999999999 Time.at(epoch).utc.iso8601 end
get_iso8601_from_time(time)
click to toggle source
# File lib/orcid_client/date.rb, line 46 def get_iso8601_from_time(time) return nil if time.blank? Time.zone.parse(time.to_s).utc.iso8601 end
get_parts_from_date_parts(date_parts)
click to toggle source
# File lib/orcid_client/date.rb, line 25 def get_parts_from_date_parts(date_parts) parts = date_parts.fetch('date-parts', []).first return { "date_parts" => [[]] } unless parts.present? { 'year' => parts[0], 'month' => parts[1], 'day' => parts[2] }.compact end
get_year_month(iso8601_time)
click to toggle source
# File lib/orcid_client/date.rb, line 12 def get_year_month(iso8601_time) return [nil, nil] if iso8601_time.nil? year = iso8601_time[0..3].to_i month = iso8601_time[5..6].to_i [year, month] end
get_year_month_day(iso8601_time)
click to toggle source
# File lib/orcid_client/date.rb, line 34 def get_year_month_day(iso8601_time) return [] if iso8601_time.nil? year = iso8601_time[0..3] month = iso8601_time[5..6] day = iso8601_time[8..9] { 'year' => year, 'month' => month, 'day' => day }.compact end