Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBS-10562: Add phrases for future (sidebar) dates
This only adds the option for cases that seem likely to happen and where we have custom phrases already. The opening and closing of a place can be announced ahead of time, and so can the dissolution of a group (but it would be strange to announce the foundation of a group before it happens, very dodgy to announce the death of a person and pretty much impossible to specify the birth of one).
- Loading branch information
1 parent
f9c1fca
commit 178a998
Showing
4 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* @flow strict | ||
* Copyright (C) 2020 MetaBrainz Foundation | ||
* | ||
* This file is part of MusicBrainz, the open internet music database, | ||
* and is licensed under the GPL version 2, or (at your option) any | ||
* later version: http://www.gnu.org/licenses/gpl-2.0.txt | ||
*/ | ||
|
||
export default function isFutureDate( | ||
givenDate: PartialDateT | null, | ||
) { | ||
const givenYear = givenDate?.year; | ||
if (givenDate == null || givenYear == null) { | ||
return false; | ||
} | ||
|
||
const now = new Date(); | ||
const currentDate = { | ||
day: now.getUTCDate(), | ||
// Months in JavaScript are 0-based. (Days and years are not.) | ||
month: now.getUTCMonth() + 1, | ||
year: now.getUTCFullYear(), | ||
}; | ||
|
||
if (givenYear > currentDate.year) { | ||
return true; | ||
} | ||
|
||
if (givenYear === currentDate.year) { | ||
if (givenDate.month == null) { | ||
return false; | ||
} | ||
if (givenDate.month > currentDate.month) { | ||
return true; | ||
} | ||
if (givenDate.month === currentDate.month) { | ||
if (givenDate.day == null) { | ||
return false; | ||
} | ||
if (givenDate.day > currentDate.day) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} |