I have a very strange behavior on an application. The server is in New York(-5 GMT timezone) and the client - me, in Romania(+2 GMT timezone) so there is a 7 hour discrepancy. The problem I'm facing is when I try to save a date, let's say 12:00(day doesn't matter), the client is sending a request with the date 12:00, the 12:00 reaches the database but when it returns the severs returns the hour 19:00. I tried to debug on local to see who messes up the date but since I have the same date on server and on client there is no discrepancy.
This is the parameter sent to server &startDate=07/25/2012%2012:00:00
And this is the result: 1343232000000 - the seconds from the epoch(if you use a converter - http://www.epochconverter.com/ - you will see that the date is in fact Wed Jul 25 2012 19:00:00
here are some code snippets :
public static void GetProfessionalsHours(List<long> ids, out List<SalonProfessional> professionals)
{
professionals = new List<SalonProfessional>();
using (SqlConnection conn = new SqlConnection(DbConfig.ConnectionString))
{
using (
SqlCommand command = new SqlCommand("GetProfessionalsHours", conn) { CommandType = CommandType.StoredProcedure })
{
conn.Open();
command.Parameters.AddWithValue("professionalIDs", ids.CommaSeparated());
using (IDataReader reader = command.ExecuteReader())
{
//get normal schedule
while (reader.Read())
{
professionals.Add(SalonProfessional.GetSalonProfessional(reader));
}
reader.NextResult();
while (reader.Read())
{
professionals.Find(p => p.ID == reader.GetInt64(1)).Hours.Add(ProfessionalHours.GetProfessionalHour(reader));
}
//get overriden hours
reader.NextResult();
while (reader.Read())
{
professionals.Find(p => p.ID == reader.GetInt64(1)).OverriddenHours.Add(ProfessionalOverriddenHour.GetProfessionalOverriddenHour(reader));
}
}
}
}
}
public static ProfessionalOverriddenHour GetProfessionalOverriddenHour(IDataReader reader)
{
return new ProfessionalOverriddenHour()
{
ID = reader.GetInt64(0),
ProfessionalId = reader.GetInt64(1),
StartDate = reader.GetDateTime(2),
EndDate = reader.GetDateTime(3),
};
}
public JsonResult CalendarData(List<long> professionalIDs, CalendarData calendarData)
{
AjaxResponse response = new AjaxResponse();
response.Success = true;
CalendarDataResponseObject responseData = new CalendarDataResponseObject();
response.Content = responseData;
try
{
List<SalonProfessional> professionals = null;
CalendarOperations.GetProfessionalsHours(professionalIDs, out professionals);
responseData.Professionals = professionals;
}
catch (Exception ex)
{
response.Success = true;
response.ErrorMessage = "Could not retrieve calendar data";
ExceptionsOperations.LogException(ex, "Could not retrieve calendar data");
}
return Json(response, JsonRequestBehavior.AllowGet);
}
The problem is on StartDate and EndDate from the ProfessionalOverriddenHour object.