Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/localize-date-to-instance-time-zone (#214)
* Remove moment Add timezone * Format * Add timezone to meeting card
- Loading branch information
Showing
17 changed files
with
27,663 additions
and
146 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,37 +1,38 @@ | ||
import moment from "moment"; | ||
|
||
import { FilterState } from "../reducer"; | ||
|
||
/** | ||
* Generate the text representation of a date range. | ||
* @param {Object} dateRange The start and end dates object. | ||
* @param {string} dateRange.start | ||
* @param {string} dateRange.end | ||
* @param {string} defaultText The default text representation, when no dates have been entered. | ||
* @return {string} The text representation. | ||
*/ | ||
const getDateText = (dateRange: FilterState<string>, defaultText: string): string => { | ||
const start = moment.utc(dateRange.start, "YYYY-MM-DD"); | ||
const end = moment.utc(dateRange.end, "YYYY-MM-DD"); | ||
const startString = start.format("MMM D, YYYY"); | ||
const endString = end.format("MMM D, YYYY"); | ||
let textRep; | ||
if (dateRange.start && dateRange.end) { | ||
if (start.year() === end.year() && start.month() === end.month()) { | ||
textRep = `${startString.split(",")[0]} - ${end.date()}, ${end.year()}`; | ||
} else if (start.year() === end.year()) { | ||
textRep = `${startString.split(",")[0]} - ${endString.split(",")[0]}, ${end.year()}`; | ||
} else { | ||
import getTimeZoneDate from "../../../utils/getTimeZoneName"; | ||
|
||
const getDateText = | ||
(language: string, timeZone: string) => | ||
(dateRange: FilterState<string>, defaultText: string): string => { | ||
const timeZoneStartDate = getTimeZoneDate(new Date(dateRange.start), timeZone); | ||
const timeZoneEndDate = getTimeZoneDate(new Date(dateRange.end), timeZone); | ||
const startString = timeZoneStartDate?.toLocaleDateString(language, { | ||
timeZone, | ||
month: "short", | ||
day: "numeric", | ||
year: | ||
timeZoneStartDate.getUTCFullYear() === timeZoneEndDate?.getUTCFullYear() | ||
? undefined | ||
: "numeric", | ||
}); | ||
const endString = timeZoneEndDate?.toLocaleDateString(language, { | ||
timeZone, | ||
month: "short", | ||
day: "numeric", | ||
year: "numeric", | ||
}); | ||
let textRep; | ||
if (timeZoneStartDate && timeZoneEndDate) { | ||
textRep = `${startString} - ${endString}`; | ||
} else if (timeZoneStartDate) { | ||
textRep = `${startString} -`; | ||
} else if (timeZoneEndDate) { | ||
textRep = `- ${endString}`; | ||
} else { | ||
textRep = defaultText; | ||
} | ||
} else if (dateRange.start) { | ||
textRep = `${startString} -`; | ||
} else if (dateRange.end) { | ||
textRep = `- ${endString}`; | ||
} else { | ||
textRep = defaultText; | ||
} | ||
return textRep; | ||
}; | ||
return textRep; | ||
}; | ||
|
||
export default getDateText; |
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
Oops, something went wrong.