0

This is the chat file exported from an instgram .json file

This is how I want to alter the date format to look like

I am trying to edit the exported chat file in .txt format and change the format of dates to look like the second picture so that file can be used is usable in chat analysis tools. The timestamp is not required to be precise right down to the second and I would rather have that upto minutes only.

I couldnt find a suitable script to make this change and I'm running ubuntu.

1
  • 1
    I would open the text file in Excel, and use Text to Columns delimited on comma, change the format of date in column A, and time in column B then concatenate them back into column C. Delete columns A & B and save the file. Quick and dirty, but gets the job done. Apr 29, 2020 at 9:28

1 Answer 1

0

This will do what you want in Ruby:

require 'date'

class DateFormatter
    def format(dates)
        formatted = []
        dates.each do |date|
            formatted << DateTime.parse(date).strftime('%-m/%d/%y,%l:%M %p')
        end
        formatted
    end
end

This is the spec file for the code above:

require_relative '../date_formatter'
RSpec.describe DateFormatter do
    context "With dates from Instagram" do 
        it "should format properly" do
            dates = ["2019-09-22,16:04:39", "2019-09-22,17:16:24"]
            res = DateFormatter.new.format(dates)
            expect(res[0]).to eq "9/22/19, 4:04 PM"
            expect(res[1]).to eq "9/22/19, 5:16 PM"
        end
    end
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.