Czy ktoś może zobaczyć, co robię źle? Assert.IsTrue(parses)
zawsze kończy się niepowodzeniem.Dlaczego ta analiza DateTime zawsze kończy się niepowodzeniem?
[TestMethod]
public void Can_Parse_To_DateTime()
{
DateTime expected = new DateTime(2011, 10, 19, 16, 01, 59);
DateTime actual;
string value = "Wed Oct 19 16:01:59 PDT 2011";
string mask = "ddd MMM dd HH:mm:ss xxx YYYY";
bool parses = DateTime.TryParseExact(value, mask,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out actual);
Assert.IsTrue(parses);
Assert.AreEqual(expected, actual);
}
Próbowałem również go zatem, z takim samym skutkiem:
[TestMethod]
public void parsing()
{
DateTime expected = new DateTime(2011, 10, 19, 16, 01, 59);
DateTime actual;
string value = "Wed Oct 19 16:01:59 PDT 2011";
string mask = "ddd MMM dd HH:mm:ss YYYY"; // note removal of "xxx "
value = value.Remove(20, 4); // removal of the "PDT "
bool parses = DateTime.TryParseExact(value, mask,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out actual);
Assert.IsTrue(parses);
Assert.AreEqual(expected, actual);
}
Rok powinien być "yyyy" (małe litery), ale nie jestem pewien, czy istnieje jakiś ciąg formatu, który zinterpretuje "PDT". –
@MattHamilton - oto odpowiedź! zmienił go i działa. Opublikuj jako odpowiedź, a ja to zaakceptuję. –
Niech @Al ma rep. :) –