Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
skatkov opened this issue Oct 21, 2017 · 4 comments
Open

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

skatkov opened this issue Oct 21, 2017 · 4 comments

Comments

@skatkov
Copy link

skatkov commented Oct 21, 2017

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
Copy link
Author

skatkov commented Oct 22, 2017

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
Copy link

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
Copy link
Author

skatkov commented Nov 7, 2017

@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
Copy link

rogerogden commented Nov 7, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants