diff --git a/PasteIntoFile/Main.cs b/PasteIntoFile/Main.cs index 9c49060..82f197a 100644 --- a/PasteIntoFile/Main.cs +++ b/PasteIntoFile/Main.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -540,6 +541,14 @@ public string Format(string format, object arg, IFormatProvider formatProvider) } throw new FormatException("Invalid format string '" + format + "'. Expected a positive integer specifying maximum length."); } + // DateTime + if (arg is DateTime dt && !string.IsNullOrEmpty(format)) { + // `j` for day of year + format = Regex.Replace(format, @"j+", m => dt.DayOfYear.ToString(new string('0', m.Value.Length))); + // `w` for week of year + var week = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dt, CultureInfo.CurrentCulture.DateTimeFormat.CalendarWeekRule, CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); + format = Regex.Replace(format, @"w+", m => week.ToString(new string('0', m.Value.Length))); + } // default formatting return string.Format("{0:" + format + "}", arg); } diff --git a/PasteIntoFile/TemplateEdit.cs b/PasteIntoFile/TemplateEdit.cs index eb71ca8..50dee8f 100644 --- a/PasteIntoFile/TemplateEdit.cs +++ b/PasteIntoFile/TemplateEdit.cs @@ -28,8 +28,9 @@ public TemplateEdit() { Settings.Default.filenameTemplate, "{0:yyyy-MM-dd HH-mm-ss}", "{0:yyyyMMdd_HHmmss}", - "{0:yyyy-MM-dd}_{1:000}", + "{0:yyyy-jjj}_{1:000}", "PasteIntoFile_{1:000}_{0:fffffff}", + "{0:yyyy-ww}/{0:ddd HHᵸmm´ss´´}", "{2:10}", }); textTemplate.Text = Settings.Default.filenameTemplate; diff --git a/README.md b/README.md index 2ee749b..109529b 100644 --- a/README.md +++ b/README.md @@ -120,12 +120,11 @@ For non-text files, the file path is copied as text in addition to the image con ### Filename template format The filename and/or subfolder template string may contain the following placeholders: -- `{0}`: The current date and time. - The format can be specified, e.g. `{0:yyyy-MM-dd HH-mm-ss}`, see [format specifiers](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings) for details. -- `{1}`: A counter for batch mode. - The format can be specified, e.g. `{1:000}` for zero padding, see [format specifiers](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings) for details. -- `{2}`: The clipboard text. - The format can be specified, e.g. `{2:15}` to limit it to 15 characters. +- `{0}`: The current date and time, e.g. `{0:yyyy-MM-dd HH-mm-ss}`. + In addition to the [standard format specifiers](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings), + `j` for day-of-year and `w` for week-of-year are supported. +- `{1}`: The save counter for batch mode. E.g. `{1:000}` for 3-digit zero padding. See [format specifiers](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings) for details. +- `{2}`: The clipboard text. E.g. `{2:15}` to limit it to 15 characters. ### Command Line