title: datetimeoffset not posting back correctly - MomentJS
body: <p><strong>Technologies</strong></p>
  
  <p>KnockoutJS, Knockout Mapping Plugin, MomentJS, SQL Server, C# Web Service</p>
  
  <p><strong>Issue</strong> </p>
  
  <p>Adding time entry via modal popup that sets the start time to 7:30am to 4:30pm.  I want this to always be the case no matter the time zone the user is in.  This appears to work fine but when I save the result via ajax it changes it to 11:30 and 20:30.  It does not include the timezone which I feel is a concern but want clarification.  I'm running local only right now so both on EST.</p>
  
  <p><strong>Thoughts</strong></p>
  
  <p>I want the database to show 7:30 -4:00 or is my thinking incorrect? I also need it to load back in properly also which currently it does but I'm afraid if my server/database in on Chicago time and user in EST it would not load back in properly.</p>
  
  <p><strong>Code</strong></p>
  
  <p><em>New Time Entry</em></p>
  
  <pre><code>self.NewTimeEntry = function () {
      var today = new Date();
  
      console.log(moment(moment().format('MM/DD/YYYY')).add(7, 'h').add(30, 'm'));
      console.log(moment(moment().format('MM/DD/YYYY')).add(16, 'h').add(30, 'm'));
  
      var newEntry = {
          ID: -1,
          EmployeeID: -1,
          WorkorderID: self.WorkorderID(),
          JobDate: today,
          Description: '',
          LunchBreak: 0.5,
          StartedOn: moment(moment().format('MM/DD/YYYY')).add(7, 'h').add(30, 'm'),
          FinishedOn: moment(moment().format('MM/DD/YYYY')).add(16, 'h').add(30, 'm')
      };
      self.EmployeeHoursModal.unshift(new EmployeeHour(self, newEntry));
  
      ScrollToTop('#' + self.WorkorderHoursModalID() + ' .modal-body')
  }
  </code></pre>
  
  <p><em>Console Results</em>
  <a href="https://i.stack.imgur.com/hIhN4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hIhN4.png" alt="enter image description here"></a></p>
  
  <p><em>Employee Hour View Model</em></p>
  
  <pre><code>function EmployeeHour(parent, dto) {
  var self = this;
  dto = dto || {};
  var mapping = { 'ignore': ['__type', '_type', 'type'] }
  
  ko.mapping.fromJS(dto, mapping, self);
  
  self.LunchBreakOptions = ko.observableArray([
      new RadioButton('No Lunch', 0, self.LunchBreak, function () { return self.LunchBreak() == 0; }),
      new RadioButton('15', .25, self.LunchBreak, function () { return self.LunchBreak() == .25; }),
      new RadioButton('30', .50, self.LunchBreak, function () { return self.LunchBreak() == .50; }),
      new RadioButton('45', .75, self.LunchBreak, function () { return self.LunchBreak() == .75; }),
      new RadioButton('1 Hour', 1, self.LunchBreak, function () { return self.LunchBreak() == 1; })
  ]);
  
  self.StartedOn = ko.observable(moment(dto.StartedOn));
  self.FinishedOn = ko.observable(moment(dto.FinishedOn));
  
  self.CalculateTotal = ko.computed(function () {
      if (self.StartedOn() != null &amp;&amp; self.FinishedOn() != null) {
          var endTime = moment.utc(self.FinishedOn()).subtract((60 * self.LunchBreak()), 'm').toDate();
          var totalTime = moment.utc(moment.utc(endTime, "DD/MM/YYYY HH:mm:ss").diff(moment.utc(self.StartedOn(), "DD/MM/YYYY HH:mm:ss"))); //.format("HH:mm");
          if (parseInt(totalTime.format('HH')) == 1) {
              return parseInt(totalTime.format('HH')) + ' Hour' + ((parseInt(totalTime.format('mm')) &gt; 0) ? ' and ' + totalTime.format('mm') + ' minutes' : '');
          } else {
              return parseInt(totalTime.format('HH')) + ' Hours' + ((parseInt(totalTime.format('mm')) &gt; 0) ? ' and ' + totalTime.format('mm') + ' minutes' : '');
          }
      } else {
          return 'None';
      }
  });
  }
  </code></pre>
  
  <p><em>Modal Popup</em><a href="https://i.stack.imgur.com/J6q0z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J6q0z.png" alt="enter image description here"></a></p>
  
  <p><em>Client Saving Code</em></p>
  
  <pre><code>self.SaveTimeEntries = function () {
      IsSaving('time entries');
  
      for (var idx = 0; idx &lt; self.EmployeeHoursModal().length; ++idx) {
          var hourDTO = {
              dto: ko.toJS(self.EmployeeHoursModal()[idx])
          };
  
          PostDTO('/WorkorderService.asmx/SaveJobHour', hourDTO, function (obj) {
              self.EmployeeHoursModal()[idx].ID(obj.ID);
          });
      }
  
      SavedSuccessfully();
  }
  </code></pre>
  
  <p><em>Server Saving Code</em>
  <a href="https://i.stack.imgur.com/tNiKz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tNiKz.png" alt="enter image description here"></a></p>