date - How can I get Breeze.js to save my timezone in my SQL DB -
we trying sort out how have user input date-time timezone , save in sql database. have column of type datetimeoffset in sql server.
$scope.saveitemchanges = function () { var td = new date(); $scope.chosenedititem.servicestatusupdatedatetimeoffset = td; $log.info( td.tostring() + "iso " + td.toisostring() + "utc " + td.toutcstring() + "json " + td.tojson()); maindataservice.savechanges() .then (savesucceededcloseedit) .fail (displayerrors) }
in database i'm not seeing timezone. rows 1007-1009 got inserted via breeze other rows testing.
basically want able capture date-time , timezone on client , store in db. when someones goes view record need able determine timezone date-time for. i'm not sure i'm missing in path client -> server stopping timezone being saved in db.
breeze date info http://www.breezejs.com/documentation/date-time
console logging:
database record:
javascript treats dates utc, can still change on server.
first, need know timezone on client , send server. can having unmapped property (i.e. won't saved db):
var unusualdate = function () { this.timezoneoffset = 0; }; em.metadatastore.registerentitytypector("unusualdate", unusualdate); var td = new date(); var ud = em.createentity("unusualdate", { creationdate: td }); ud.setproperty("timezoneoffset", td.gettimezoneoffset()/-60);
then, on server beforesaveentity or beforesaveentities, retrieve timezone offset , reset date accordingly:
var timezoneoffset = convert.toint32(entityinfo.unmappedvaluesmap["timezoneoffset"]); unusualdate udate = entityinfo.entity unusualdate; udate.creationdate = udate.creationdate.tooffset(new timespan(timezoneoffset, 0, 0));
if not familiar beforesaveentity , beforesaveentities, can take @ documentation @ http://www.breezejs.com/documentation/efcontextprovider-methods.
Comments
Post a Comment