Discrepancy in date-time format.
Category
- [ ] Enhancement
- [x] Bug
- [ ] Question
- [x] Documentation gap/issue
Version
Please specify what version of the library you are using: [3.7.0]
Please specify what version(s) of SharePoint you are targeting: [web]
Issue
There are two ways to get the item of, say, a folder.
const myFolder = sp.web.folders.getByUrl("path/to/My Folder");
const itemAllFields = await myFolder.listItemAllFields();
assert(itemAllFields.Created === "2022-10-08T02:20:30"); // no timezone
// and
const item = await myFolder.getItem().then(item => item());
assert(item.Created === "2022-10-08T09:20:30Z") // UTC
These two methods basically return the same thing but with discrepancy in the way date-time fields are formatted.
.listItemAllFields()returns a timezoneless date-time string where the date-time is in the timezone configured for the server. In the above case, Pacific Time (with daylight saving), i.e. UTC-7..getItem().then(item => item())returns date-time strings as UTC with aZsuffix.
The same applies for other date-time fields. Also observed that these result in having different odata.id.
Expected
All date-time are formatted as UTC. Even better, Date.
Remarks
If this is expected, it should be well documented. It took quite a while to figure what was going on.
I totally understand your frustration in the lack of consistency, but this library does not, for obvious reasons, try to redocument the behavior of the REST endpoints themselves; this library is only a fluent way to make those calls. Essentially, we just pass through the parsed JSON payload from the network call. If you have questions or concerns about the endpoint themselves then you need to look at Microsoft's documentation, although I can warn you ahead it's not the best.
Yes, I've come across a few more inconsistency cases and this library is not to blame.
It may be worth documenting the mere fact that returned data is a passthrough of what is returned by the endpoints and that the endpoints documentation, despite lacking, should be consulted. I.e. for each method, provide a link to the endpoint being called. This would definitely be helpful to people coming to this library first (like me). I.e. not already familiar with SharePoints REST api.
Closing this issue as answered. If you have additional questions or we did not answer your question, please open a new issue, ref this issue, and provide any additional details available. Thank you!
This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.