# -*- coding: utf-8 -*-
require 'Date'
def payings_helper(cutoff_date)
	(y,m,d) =	cutoff_date.gsub(/\"/,'').split(/-/)
	return "\"" + ((Date::new(y.to_i,m.to_i,1) >> 1) - 1).to_s + "\""
end

csv = '/tmp/payings.csv'

open(csv) do |file|
  while line = file.gets()
    array = line.split(',')
    array[8] = payings_helper(array[8])
    puts array.inject{|r,i| r + "," + i}
  end
end
