Change no-year sentinel value to 0004
This allows setting the date "Feb 29" with no year, since the year 0004 is a leap year in the Gregorian calendar, while the year 0001 isn't.
This commit is contained in:
parent
9394b14a38
commit
30ed293dc6
@ -128,7 +128,8 @@ namespace PluralKit
|
||||
|
||||
public PrivacyLevel MemberPrivacy { get; set; }
|
||||
|
||||
/// Returns a formatted string representing the member's birthday, taking into account that a year of "0001" is hidden
|
||||
/// Returns a formatted string representing the member's birthday, taking into account that a year of "0001" or "0004" is hidden
|
||||
/// Before Feb 10 2020, the sentinel year was 0001, now it is 0004.
|
||||
[JsonIgnore] public string BirthdayString
|
||||
{
|
||||
get
|
||||
@ -136,7 +137,7 @@ namespace PluralKit
|
||||
if (Birthday == null) return null;
|
||||
|
||||
var format = LocalDatePattern.CreateWithInvariantCulture("MMM dd, yyyy");
|
||||
if (Birthday?.Year == 1) format = LocalDatePattern.CreateWithInvariantCulture("MMM dd");
|
||||
if (Birthday?.Year == 1 || Birthday?.Year == 4) format = LocalDatePattern.CreateWithInvariantCulture("MMM dd");
|
||||
return format.Format(Birthday.Value);
|
||||
}
|
||||
}
|
||||
|
@ -105,10 +105,12 @@ namespace PluralKit
|
||||
"MM/dd" // 01/01
|
||||
});
|
||||
|
||||
// Giving a template value so year will be parsed as 0001 if not present
|
||||
// Giving a template value so year will be parsed as 0004 if not present
|
||||
// This means we can later disambiguate whether a null year was given
|
||||
// We use the basis year 0004 (rather than, say, 0001) because 0004 is a leap year in the Gregorian calendar
|
||||
// which means the date "Feb 29, 0004" is a valid date. 0001 is still accepted as a null year for legacy reasons.
|
||||
// TODO: should we be using invariant culture here?
|
||||
foreach (var pattern in patterns.Select(p => LocalDatePattern.CreateWithInvariantCulture(p).WithTemplateValue(new LocalDate(0001, 1, 1))))
|
||||
foreach (var pattern in patterns.Select(p => LocalDatePattern.CreateWithInvariantCulture(p).WithTemplateValue(new LocalDate(0004, 1, 1))))
|
||||
{
|
||||
var result = pattern.Parse(str);
|
||||
if (result.Success) return result.Value;
|
||||
|
@ -51,7 +51,7 @@ The following three models (usually represented in JSON format) represent the va
|
||||
|description|string?|Yes|1000-character limit.|
|
||||
|color|color?|Yes|6-char hex (eg. `ff7000`), sans `#`.|
|
||||
|avatar_url|url?|Yes|Not validated server-side.|
|
||||
|birthday|date?|Yes|ISO-8601 (`YYYY-MM-DD`) format, year of `0001` means hidden year.|
|
||||
|birthday|date?|Yes|ISO-8601 (`YYYY-MM-DD`) format, year of `0001` or `0004` means hidden year. Birthdays set after 2020-02-10 use `0004` as a sentinel year, but both options are recognized as valid.|
|
||||
|prefix|string?|Yes|Deprecated. Use `proxy_tags` instead.|
|
||||
|suffix|string?|Yes|Deprecated. Use `proxy_tags` instead.|
|
||||
|proxy_tags|ProxyTag[]|Yes (entire array)|An array of ProxyTag (see below) objects, each representing a single prefix/suffix pair.|
|
||||
@ -431,6 +431,8 @@ The returned system and member's privacy settings will be respected, and as such
|
||||
```
|
||||
|
||||
## Version history
|
||||
* 2020-02-10
|
||||
* Birthdates with no year can now be stored using `0004` as a year, for better leap year support. Both options remain valid and either may be returned by the API.
|
||||
* 2020-01-08
|
||||
* Added privacy support, meaning some responses will now lack information or return 403s, depending on the specific system and member's privacy settings.
|
||||
* 2019-12-28
|
||||
|
Loading…
Reference in New Issue
Block a user