public static void Main() { // TryMatch() can get a single match if (IsoDate.TryMatch("2021-02-03T01:23:45.678Z", out var isoDate)) { Console.WriteLine($"IsoDate: year={isoDate.Year} month={isoDate.Month} day={isoDate.Day}"); } // IsMatch() allows simple validity checks var testUsernames = new[] { "foo-bar", "foobar", "3foobar", "foo-bar-", "-foo-bar", "foo--bar" }; foreach (var username in testUsernames) { Console.WriteLine($"GithubUsername: {username}: {GithubUsername.IsMatch(username)}"); } // Matches() allows iterating through several matches var sourceText = "This is some example text showing URL matching, for https://example.org. " + "It will match with IPs http://192.0.2.1 or ftp://some.site.example.org and" + "also long ones https://user:[email protected]:4433/some/path?query=abc¶m=234."; foreach (var url in UrlRegex.Matches(sourceText)) { Console.WriteLine($"Found URL, scheme = {url.Scheme}, fullhost = {url.Fullhost}"); foreach (var path in url.Path) { Console.WriteLine(" " + path); } } }
public static new JsonDate Parse(string text) { if (text == null) { throw new ArgumentNullException(nameof(text)); } // TODO support: unixtimeseconds.partialseconds if (text.Length > 4 && _IsNumber(text)) // UnixTime { var date = DateTimeOffset.FromUnixTimeSeconds(long.Parse(text)); return(new JsonDate(date)); } else if (text.Length <= 4 || text[4] == '-') // ISO: 2012- { return(new JsonDate(IsoDate.Parse(text).ToDateTimeOffset())); } else { // NOT ISO ENCODED // "Thu, 5 Apr 2012 16:59:01 +0200", return(new JsonDate(DateTimeOffset.Parse(text))); } }
public void Parse() { var text = @"{ ""status"": ""pending"", ""expires"": ""2015-03-01T14:09:00Z"", ""identifiers"": [ { ""type"": ""dns"", ""value"": ""example.com"" }, { ""type"": ""dns"", ""value"": ""www.example.com"" } ], ""notBefore"": ""2016-01-01T00:00:00Z"", ""notAfter"": ""2016-01-08T00:00:00Z"", ""authorizations"": [ ""https://example.com/acme/authz/1234"", ""https://example.com/acme/authz/2345"" ], ""finalize"": ""https://example.com/acme/acct/1/order/1/finalize"", ""certificate"": ""https://example.com/acme/cert/1234"" }"; var model = JsonObject.Parse(text).As <Order>(); Assert.Equal(OrderStatus.Pending, model.Status); Assert.Equal(IsoDate.Parse("2015-03-01T14:09:00Z").ToUtcDateTime(), model.Expires); Assert.Equal("https://example.com/acme/acct/1/order/1/finalize", model.FinalizeUrl); Assert.Equal("https://example.com/acme/cert/1234", model.CertificateUrl); Assert.Equal(new Identifier("dns", "example.com"), model.Identifiers[0]); Assert.Equal(new Identifier("dns", "www.example.com"), model.Identifiers[1]); Assert.Equal("https://example.com/acme/authz/1234", model.AuthorizationUrls[0]); Assert.Equal("https://example.com/acme/authz/2345", model.AuthorizationUrls[1]); }
public void Parse() { var model = JsonObject.Parse(@"{ ""status"": ""valid"", ""expires"": ""2015-03-01T14:09:00Z"", ""identifier"": { ""type"": ""dns"", ""value"": ""example.org"" }, ""challenges"": [ { ""url"": ""https://example.com/authz/1234/0"", ""type"": ""http-01"", ""status"": ""valid"", ""token"": ""DGyRejmCefe7v4NfDGDKfA"" ""validated"": ""2014-12-01T12:05:00Z"", ""keyAuthorization"": ""SXQe-2XODaDxNR...vb29HhjjLPSggwiE"" } ], ""wildcard"": false }").As <Authorization>(); Assert.Equal(IsoDate.Parse("2015-03-01T14:09:00Z").ToUtcDateTime(), model.Expires); Assert.Equal(AuthorizationStatus.Valid, model.Status); Assert.Equal(new Identifier("dns", "example.org"), model.Identifier); Assert.False(model.Wildcard.Value); var challenge = model.Challenges[0]; Assert.Equal("http-01", challenge.Type); Assert.Equal("https://example.com/authz/1234/0", challenge.Url); Assert.Equal(ChallengeStatus.Valid, challenge.Status); Assert.Equal(IsoDate.Parse("2014-12-01T12:05:00Z").ToUtcDateTime(), challenge.Validated); Assert.Equal("DGyRejmCefe7v4NfDGDKfA", challenge.Token); }
public string ToIsoString() { return(IsoDate.FromDateTimeOffset(value).ToString()); }
public void writeInstance(XmlSerializer writer, Object obj) { writer.text(IsoDate.dateToString((DateTime)obj, IsoDate.DATE_TIME)); }
public Object readInstance(XmlPullParser parser, String namespace_, String name, PropertyInfo expected) { return(IsoDate.stringToDate(parser.nextText(), IsoDate.DATE_TIME)); }