Skip to content

Commit

Permalink
do more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
perunt committed Aug 27, 2023
1 parent 3402e36 commit dbf4f4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
29 changes: 14 additions & 15 deletions src/libs/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,28 @@ function getDateStringFromISOTimestamp(isoTimestamp) {
}

/**
* @returns {string} example: 2023-05-16
* @returns {string} example: 2023-05-16 05:34:14
*/
function getThirtyMinutesFromNow() {
return moment().add(30, 'minutes').format('YYYY-MM-DD HH:mm:ss');
}

/**
* @returns {string} example: 2023-05-16 05:34:14
*/
function getOneHourFromNow() {
return moment().add(1, 'hours').format('YYYY-MM-DD HH:mm:ss');
}

/**
* @returns {string} example: 2023-05-16
* @returns {string} example: 2023-05-16 05:34:14
*/
function getEndOfToday() {
return moment().endOf('day').format('YYYY-MM-DD HH:mm:ss');
}

/**
* @returns {string} example: 2023-05-16
* @returns {string} example: 2023-05-16 05:34:14
*/
function getEndOfWeekFromNow() {
return moment().add(7, 'days').format('YYYY-MM-DD HH:mm:ss');
Expand All @@ -319,33 +322,29 @@ function getEndOfWeekFromNow() {
/**
* @param {string} time
* @returns {string} example: 2023-05-16
* it's kind of 'newer' date
*/
function extractDate(time) {
return moment(time).format('YYYY-MM-DD');
}

/**
* @param {string} dateTimeString
* @returns {string} example: 2023-05-16
* it's kind of 'newer' date
* @returns {string} example: 11:10
*/
function extractTime(dateTimeString) {
return moment(dateTimeString).format('hh:mm');
}
/**
* @param {string} dateTimeString
* @returns {string} example: 2023-05-16
* it's kind of 'newer' date
* @returns {string} example: 11:10 PM
*/
function extractTime12Hour(dateTimeString) {
return moment(dateTimeString).format('hh:mm A');
}

/**
* @param {string} dateTimeString
* @returns {string} example: 2023-05-16
* it's kind of 'newer' date
* @returns {string} example: 2023-05-16 11:10 PM
*/
function formatDateTo12Hour(dateTimeString) {
if (!dateTimeString) return '';
Expand All @@ -354,9 +353,9 @@ function formatDateTo12Hour(dateTimeString) {

/**
* @param {string} type - one of the values from CONST.CUSTOM_STATUS_TYPES
* @returns {string} example: 2023-05-16
* @returns {string} example: 2023-05-16 11:10:00 or ''
*/
function getDateBasedFromType(type) {
function getDateFromStatusType(type) {
switch (type) {
case CONST.CUSTOM_STATUS_TYPES.THIRTY_MINUTES:
return getThirtyMinutesFromNow();
Expand All @@ -377,7 +376,7 @@ function getDateBasedFromType(type) {
* @param {string} data - one of the values from CONST.CUSTOM_STATUS_TYPES or data in format YYYY-MM-DD HH:mm
* @returns {string} example: 2023-05-16 11:10 PM or 'Today'
*/
function getDateForTitleBasedFromType(data) {
function getLocalizedTimePeriodDescription(data) {
const {translateLocal} = Localize;
switch (data) {
case getEndOfToday():
Expand Down Expand Up @@ -513,7 +512,7 @@ const DateUtils = {
getThirtyMinutesFromNow,
getEndOfToday,
getEndOfWeekFromNow,
getDateBasedFromType,
getDateFromStatusType,
getOneHourFromNow,
extractDate,
extractTime,
Expand All @@ -524,7 +523,7 @@ const DateUtils = {
parseTimeTo12HourFormat,
areDatesIdentical,
getTimePeriod,
getDateForTitleBasedFromType,
getLocalizedTimePeriodDescription,
};

export default DateUtils;
10 changes: 5 additions & 5 deletions src/pages/settings/Profile/CustomStatus/StatusClearAfterPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const propTypes = {
* @param {string} data - one of the values from CONST.CUSTOM_STATUS_TYPES or data in format YYYY-MM-DD HH:mm
* @returns {string}
*/
function getDateBasedFromType(data) {
function getInitialDateBasedFromStatusType(data) {
switch (data) {
case DateUtils.getEndOfToday():
return CONST.CUSTOM_STATUS_TYPES.AFTER_TODAY;
Expand All @@ -58,7 +58,7 @@ function StatusClearAfterPage({currentUserPersonalDetails, customStatus}) {
const clearAfter = lodashGet(currentUserPersonalDetails, 'status.clearAfter', '');
const draftClearAfter = lodashGet(customStatus, 'clearAfter', '');
const customDateTemporary = lodashGet(customStatus, 'customDateTemporary', '');
const [draftPeriod, setDraftPeriod] = useState(getDateBasedFromType(clearAfter || draftClearAfter));
const [draftPeriod, setDraftPeriod] = useState(getInitialDateBasedFromStatusType(clearAfter || draftClearAfter));
const localesToThemes = useMemo(
() =>
_.map(CONST.CUSTOM_STATUS_TYPES, (value, key) => ({
Expand All @@ -73,10 +73,10 @@ function StatusClearAfterPage({currentUserPersonalDetails, customStatus}) {
const onSubmit = () => {
let calculatedDraftDate = '';
if (draftPeriod === CONST.CUSTOM_STATUS_TYPES.CUSTOM) {
calculatedDraftDate = customDateTemporary || draftClearAfter;
calculatedDraftDate = customDateTemporary;
} else {
const selectedRange = _.find(localesToThemes, (item) => item.isSelected);
calculatedDraftDate = DateUtils.getDateBasedFromType(selectedRange.value);
calculatedDraftDate = DateUtils.getDateFromStatusType(selectedRange.value);
}

User.updateDraftCustomStatus({clearAfter: calculatedDraftDate, customDateTemporary: calculatedDraftDate});
Expand All @@ -87,7 +87,7 @@ function StatusClearAfterPage({currentUserPersonalDetails, customStatus}) {
(mode) => {
if (mode.value === draftPeriod) return;
User.updateDraftCustomStatus({
customDateTemporary: mode.value === CONST.CUSTOM_STATUS_TYPES.CUSTOM ? DateUtils.getOneHourFromNow() : DateUtils.getDateBasedFromType(mode.value),
customDateTemporary: mode.value === CONST.CUSTOM_STATUS_TYPES.CUSTOM ? DateUtils.getOneHourFromNow() : DateUtils.getDateFromStatusType(mode.value),
});
setDraftPeriod(mode.value);
},
Expand Down

0 comments on commit dbf4f4e

Please sign in to comment.