プロジェクト

全般

プロフィール

Vote #76175

完了

Unexpected milliseconds in JSON time attributes

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
REST API_32
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
32
version_id:
92
issue_org_id:
19354
author_id:
7834
assigned_to_id:
1
comments:
5
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

our original request #5901 was about exposing Redmine version through REST API so that clients would know what functionality is supported by the server.
that request is still relevant, but I decided to submit a smaller feature request about date formats.

Redmine 3.x broke backward compatibility - the date format used in REST responses is different from Redmine 2.6:

From redmine 2.6.0: "updated_on":"2015-01-23T00:15:24Z"
From redmine 3.0.0: "updated_on":"2015-01-29T10:06:19.000Z"

one of our users submitted this bug report: https://github.com/taskadapter/redmine-java-api/pull/175

if we could query Redmine to see its version, we could pick the right date format instead of guessing... now we will have to check "are there 3 more digits after this and before that?"..

but a better option would be querying Redmine to see what date format it uses for long dates and short dates - because this is what the library actually cares about.


journals

The date format is not supposed to change in 3.0.0. There was a problem that is fixed for 3.0.1 (#19065), but it was different. Here is what I get for an issue with current trunk:

<pre>
<created_on>2015-03-13T11:01:27Z</created_on>
<updated_on>2015-03-13T11:02:17Z</updated_on>
</pre>

Can you give more details about how to reproduce this?
--------------------------------------------------------------------------------
Redmine uses @#xmlschema@ without arguments to format dates in XML output, which gives 0 decimals by default:

<pre>
irb(main):002:0> Time.now.utc.xmlschema
=> "2015-03-14T09:04:32Z"
irb(main):003:0> Time.now.utc.xmlschema(3)
=> "2015-03-14T09:04:41.221Z"
</pre>

source:/trunk/lib/redmine/views/builders/xml.rb
--------------------------------------------------------------------------------
Note that I am using JSon instead of XML.

This is my Redmine 3.0.0 on the test server: http://76.126.10.142/redmine/issues/2.json
(use "test"/"test" credentials).

the payload it returns is

<pre>
{
"issue": {
"id": 2,
"project": {
"id": 11,
"name": "permanent test project"
},
"tracker": {
"id": 1,
"name": "Bug"
},
"status": {
"id": 1,
"name": "New"
},
"priority": {
"id": 2,
"name": "Normal"
},
"author": {
"id": 1,
"name": "Redmine Admin"
},
"subject": "test123",
"description": "",
"done_ratio": 0,
"spent_hours": 0.0,
"custom_fields": [
{
"id": 1,
"name": "my_custom_1"
},
{
"id": 2,
"name": "custom_boolean_1",
"value": ""
},
{
"id": 3,
"name": "custom_multi_list",
"multiple": true,
"value": [
"V1",
"V3"
]
}
],
"created_on": "2015-03-12T20:10:27.000Z",
"updated_on": "2015-03-12T21:46:21.000Z"
}
}
</pre>

server info:
<pre>
Environment:
Redmine version 3.0.0.stable
Ruby version 2.0.0-p598 (2014-11-13) [x86_64-linux]
Rails version 4.2.0
Environment production
Database adapter Mysql2
SCM:
Git 1.9.1
Filesystem
Redmine plugins:
no plugin installed
</pre>

even if you change Json format to match XML now, Redmine 3.0.0 version will still have this other format...
how can external clients detect the proper format? one way is to search for "." in the date string and thus detect that there are milliseconds there.
but a better (much more resilient) way would be for the server to provide the formatting string either in a separate REST endpoint ("give me all server settings please") or - even better - right inside the "issues/issue/all others" response:
"hey, you asked for issues, here is the result, and by the way, the date format I use is xxx-xxx-xxx-xxx-..."- this would make the response much easier to understand and client libraries (like Redmine Java API) - easier to maintain.

--------------------------------------------------------------------------------
This change was not intentional, this was changed by Rails 4. So the requested information about the time format would have been wrong. I've fixed this format and added a test to make sure it stays like this.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

Admin Redmine さんが約4年前に更新

  • カテゴリREST API_32 にセット
  • 対象バージョン3.0.1_92 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0