TSheetsTeam / api_ruby

MIT License
1 stars 13 forks source link

'start_date' date is not in valid ISO-8601 date only format #5

Open skatkov opened 7 years ago

skatkov commented 7 years ago

Format sent to tsheet api is not accepted.

TSheets::ExpectationFailedError: TSheets::ExpectationFailedError: 'start_date' date [Sat, 10/07/17 12:00 AM] is not in valid ISO-8601 date only format

code:

timesheet = TsheetsAdapter.new.timesheets
timesheet.each {|record| puts record.inspect }

class TsheetsAdapter
  def initialize
    @tsheets_api = TSheets::API.new do |config|
      config.access_token = TSHEETS_KEY
    end
  end

  def timesheets
    @tsheets_api.timesheets.where(
      start_date: 2.weeks.ago.to_date,
      end_date: DateTime.now.to_date)
  end
end

system:

OSX ruby -v ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin15]

skatkov commented 7 years ago

Here is a resulting request to tsheets server. Didn't yeat found where this uri is formed.

+    method: get
+    uri: https://rest.tsheets.com/api/v1/timesheets?modified_since=Sat,%2010/07/17%20%201:52%20PM&page=0
+    body:
+      encoding: US-ASCII
+      string: ''
rogerogden commented 7 years ago

Hi, @skatkov,

The reason you're obtaining the error is that the variable start_date isn't in the expected format. You need to provide the date in the ISO-8601 format. In your case, this would be 2017-10-17.

If you're using Rails, you can convert your start_date variable to a Time object and then call start_date.to_time.iso8601 to get it in a valid format.

I hope that helps. If you have any questions, let me know!

skatkov commented 7 years ago

@rogerogden I've tried that before, unfortunately gem demands certain object (DateTime) -- using start_date.to_time.iso8601 returns a string and gem throws error for that, demanding to provide DateTime.

Unfortunately, DateTime later on get's formatted not according to iso8601. I'm really not sure why that happens.

rogerogden commented 7 years ago

@skatkov I think you might be able to get away with passing the returned string from the start_date.to_time.iso8601 call to a DateTime object's parse function. Here's the documentation.