pnpjs icon indicating copy to clipboard operation
pnpjs copied to clipboard

Discrepancy in date-time format.

Open gomain opened this issue 3 years ago • 1 comments

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 a Z suffix.

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.

gomain avatar Oct 08 '22 15:10 gomain

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.

juliemturner avatar Oct 14 '22 17:10 juliemturner

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.

gomain avatar Oct 15 '22 14:10 gomain

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!

patrick-rodgers avatar Oct 20 '22 17:10 patrick-rodgers

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.

github-actions[bot] avatar Oct 23 '22 02:10 github-actions[bot]