Use a class method to consolidate timestamp conversion

This commit is contained in:
Stan Hu 2018-07-28 21:48:37 -07:00
parent ae6b48d20f
commit dd937377cf
4 changed files with 10 additions and 6 deletions

View File

@ -38,11 +38,11 @@ module BitbucketServer
def merge_timestamp
timestamp = raw.dig('commit', 'committerTimestamp')
Time.at(timestamp / 1000.0) if timestamp.is_a?(Integer)
self.class.convert_timestamp(timestamp)
end
def created_at
Time.at(created_date / 1000) if created_date.is_a?(Integer)
self.class.convert_timestamp(created_date)
end
private

View File

@ -12,6 +12,10 @@ module BitbucketServer
def self.decorate(entries)
entries.map { |entry| new(entry)}
end
def self.convert_timestamp(time_usec)
Time.at(time_usec / 1000) if time_usec.is_a?(Integer)
end
end
end
end

View File

@ -40,11 +40,11 @@ module BitbucketServer
end
def created_at
Time.at(created_date / 1000) if created_date.is_a?(Integer)
self.class.convert_timestamp(created_date)
end
def updated_at
Time.at(updated_date / 1000) if updated_date.is_a?(Integer)
self.class.convert_timestamp(created_date)
end
# Bitbucket Server supports the ability to reply to any comment

View File

@ -34,11 +34,11 @@ module BitbucketServer
end
def created_at
Time.at(created_date / 1000) if created_date.is_a?(Integer)
self.class.convert_timestamp(created_date)
end
def updated_at
Time.at(updated_date / 1000) if created_date.is_a?(Integer)
self.class.convert_timestamp(updated_date)
end
def title