I've run into a strange problem with SharePoint Online.
When updating or creating entries in a list using the Client Object Model, the modified date on the affected list item seems to be stored with the wrong timezone.
Our Office 365 server is at UTC -7 (I assume it's probably on Redmond time, even if it's not actually physically there), and I am at UTC +1. If I create a record using C# on the server, the modified date is stored with the current date and time at UTC -7. However, if I store a record from the client using JavaScript, the record is stored with my current time, but is also at UTC -7!
e.g.
if current time = 13:07 GMT
my local time = 14:07 UTC +1
storing on the server = 06:07 UTC -7
storing via the client = 14:07 UTC -7 (e.g. 8 hours in the future!)
I am not setting the modified date directly - I'm relying on SharePoint to track this information correctly.
My client script looks like this:
function addRow() {
//Create a new record
var context = SP.ClientContext.get_current();
var extList = context.get_site().get_rootWeb().get_lists().getByTitle(options.listTitle);
var itemCreateInfo = new SP.ListItemCreationInformation();
var listItem = extList.addItem(itemCreateInfo);
//Set the values
listItem.set_item('Current', data.query.results.quote.LastTradePriceOnly);
listItem.set_item('Title', 'results');
listItem.set_item('TradeDate', tradeDate);
listItem.set_item('TradeDateStamp', tradeDate.getTime());
listItem.update();
context.load(listItem);
context.executeQueryAsync(
Function.createDelegate(this, addListItemSucceeded),
Function.createDelegate(this, addListItemFailed)
);
function addListItemSucceeded() {
console.log('Row ' + data.query.count + ' added OK. New ID is ' + listItem.get_id());
}
function addListItemFailed(sender, args) {
console.log('Failed to add row ' + data.query.count + '. ' + args.get_message() + '\n' + args.get_stackTrace());
console.log(data);
}
}
Am I doing something wrong? Or is this a bug with SharePoint Online?
Update: The problem occurs when I try to retrieve the value of the Modified date using the Server Object Model:
DateTime lastUpdateDate = DateTime.MinValue;
var web = SPContext.Current.Site.RootWeb;
SPList list = web.Lists[ListName];
SPListItemCollection items = list.GetItems();
foreach (SPListItem i in items)
{
DateTime modified = (DateTime)i["Modified"];
if (modified > lastUpdateDate)
{
lastUpdateDate = modified;
}
}
// lastUpdateDate is in the future if a client in a timezone east of Redmond
// updated the data using the client object model