public void SerializeFormattedDateTimeInvariantCulture()
    {
      IsoDateTimeConverter converter = new IsoDateTimeConverter() { DateTimeFormat = "F", Culture = CultureInfo.InvariantCulture };

      DateTime d = new DateTime(2000, 12, 15, 22, 11, 3, 0, DateTimeKind.Utc);
      string result;

      result = JsonConvert.SerializeObject(d, converter);
      Assert.AreEqual(@"""Friday, 15 December 2000 22:11:03""", result);

      Assert.AreEqual(d, JsonConvert.DeserializeObject<DateTime>(result, converter));

      d = new DateTime(2000, 12, 15, 22, 11, 3, 0, DateTimeKind.Local);
      result = JsonConvert.SerializeObject(d, converter);
      Assert.AreEqual(@"""Friday, 15 December 2000 22:11:03""", result);
    }
    public void SerializeDateTime()
    {
      IsoDateTimeConverter converter = new IsoDateTimeConverter();

      DateTime d = new DateTime(2000, 12, 15, 22, 11, 3, 55, DateTimeKind.Utc);
      string result;

      result = JsonConvert.SerializeObject(d, converter);
      Assert.AreEqual(@"""2000-12-15T22:11:03.055Z""", result);

      Assert.AreEqual(d, JsonConvert.DeserializeObject<DateTime>(result, converter));

      d = new DateTime(2000, 12, 15, 22, 11, 3, 55, DateTimeKind.Local);
      result = JsonConvert.SerializeObject(d, converter);
      Assert.AreEqual(@"""2000-12-15T22:11:03.055" + d.GetUtcOffsetText() + @"""", result);
    }
    public void PropertiesShouldBeSet()
    {
      IsoDateTimeConverter converter = new IsoDateTimeConverter();
      Assert.AreEqual(CultureInfo.CurrentCulture, converter.Culture);
      Assert.AreEqual(string.Empty, converter.DateTimeFormat);
      Assert.AreEqual(DateTimeStyles.RoundtripKind, converter.DateTimeStyles);

      converter = new IsoDateTimeConverter()
      {
        DateTimeFormat = "F",
        Culture = CultureInfo.InvariantCulture,
        DateTimeStyles = DateTimeStyles.None
      };

      Assert.AreEqual(CultureInfo.InvariantCulture, converter.Culture);
      Assert.AreEqual("F", converter.DateTimeFormat);
      Assert.AreEqual(DateTimeStyles.None, converter.DateTimeStyles);
    }
    public void SerializeCustomFormattedDateTime()
    {
      IsoDateTimeConverter converter = new IsoDateTimeConverter
                                         {
                                           DateTimeFormat = "dd/MM/yyyy",
                                           Culture = CultureInfo.InvariantCulture
                                         };

      string json = @"""09/12/2006""";

      DateTime d = JsonConvert.DeserializeObject<DateTime>(json, converter);

      Assert.AreEqual(9, d.Day);
      Assert.AreEqual(12, d.Month);
      Assert.AreEqual(2006, d.Year);
    }
    public void SerializeDateTimeOffset()
    {
      IsoDateTimeConverter converter = new IsoDateTimeConverter();

      DateTimeOffset d = new DateTimeOffset(2000, 12, 15, 22, 11, 3, 55, TimeSpan.Zero);
      string result;

      result = JsonConvert.SerializeObject(d, converter);
      Assert.AreEqual(@"""2000-12-15T22:11:03.055+00:00""", result);

      Assert.AreEqual(d, JsonConvert.DeserializeObject<DateTimeOffset>(result, converter));
    }
    public void SerializeDateTimeCulture()
    {
      IsoDateTimeConverter converter = new IsoDateTimeConverter() { Culture = CultureInfo.GetCultureInfo("en-NZ") };

      string json = @"""09/12/2006""";

      DateTime d = JsonConvert.DeserializeObject<DateTime>(json, converter);

      Assert.AreEqual(9, d.Day);
      Assert.AreEqual(12, d.Month);
      Assert.AreEqual(2006, d.Year);
    }