Inspired by Go's Time.Format Layout, this package allows you to produce a custom .NET date/time format by providing the layout of a reference date formatted example.
var formatFactory = new FormatFactory();
var dateFormat = formatFactory.FormatByParsing("January 02, 2006"); // Produces "MMMM dd, yyyy"
By default, the factory uses the current culture, and the reference date/time
Mon Jan 2 15:04:05 -07:00 2006
You can use specific cultures (IFormatProvider
s), and another reference date. You can also specify that you only care about formatting date components or time components.
var frenchCulture = CultureInfo.GetCultureInfo("fr");
var formatFactory = new FormatFactory(new DateTime(2006, 1, 2), ReferenceKind.DateOnly, frenchCulture);
var format = formatFactory.FormatByParsing("janvier '06"); // Produces "MMMM 'yy"