-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Date objects change value on update #34
Comments
Actually, nevermind. Serializer is using |
ok, solved it by adding custom date converter to all the fields with public class SfDateConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
{
writer.WriteValue(((DateTime)value).ToString("yyyy-MM-ddT00:00:00+00:00"));
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
if(reader.Value==null)return null;
return DateTime.ParseExact(reader.Value.ToString(), "yyyy-MM-dd", CultureInfo.InvariantCulture);
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(DateTime);
}
} I wonder if the model generator could be extended to apply this JsonConverter on all |
Definitely sounds like it would be useful to handle the SF Date types more cleanly, and to avoid any accidental date shifts due to TZ. |
I could make required changes to the model generator next weekend and submit a PR. |
Ill go ahead and take it for now, im going to look at a couple ways to integrate it into the client, I had been considering adding a couple new attributes to tag the models with SF types anyways. |
I have a custom object and couple of
Date
fields one them. Everytime I update object, those get updated as well. I update my custom object by first reading it withGetObjectById<>
, then set values only for the fields I need to update and not touching the date (exactly SF Date filed, not DateTime) fielfds.The date filed has time set to zeros, but the the serializer adds my localtime offset, as you can see below:
Is there a way to configure the client to utilize DateTimeZoneHandling option [DateTimeZoneHandling.Utc]? Salesforece stores datetimes in UTC, therefore, when my "updated" object is stored, SF converts
2021-03-06T00:00:00+04:00
to2021-03-05T00:00:00+00:00
The text was updated successfully, but these errors were encountered: