UNPKG

@sendbird/uikit-react

Version:

Sendbird UIKit for React: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.

167 lines (159 loc) 5.15 kB
import { i as isSameDay } from './bundle-Bc7Qfnu1.js'; import { r as requiredArgs, t as toDate } from './bundle-Bw_RT7A_.js'; import { t as toInteger } from './bundle-Bq-Lo_oj.js'; /** * @name isToday * @category Day Helpers * @summary Is the given date today? * @pure false * * @description * Is the given date today? * * > ⚠️ Please note that this function is not present in the FP submodule as * > it uses `Date.now()` internally hence impure and can't be safely curried. * * @param {Date|Number} date - the date to check * @returns {Boolean} the date is today * @throws {TypeError} 1 argument required * * @example * // If today is 6 October 2014, is 6 October 14:00:00 today? * const result = isToday(new Date(2014, 9, 6, 14, 0)) * //=> true */ function isToday(dirtyDate) { requiredArgs(1, arguments); return isSameDay(dirtyDate, Date.now()); } /** * @name isSameYear * @category Year Helpers * @summary Are the given dates in the same year? * * @description * Are the given dates in the same year? * * @param {Date|Number} dateLeft - the first date to check * @param {Date|Number} dateRight - the second date to check * @returns {Boolean} the dates are in the same year * @throws {TypeError} 2 arguments required * * @example * // Are 2 September 2014 and 25 September 2014 in the same year? * const result = isSameYear(new Date(2014, 8, 2), new Date(2014, 8, 25)) * //=> true */ function isSameYear(dirtyDateLeft, dirtyDateRight) { requiredArgs(2, arguments); var dateLeft = toDate(dirtyDateLeft); var dateRight = toDate(dirtyDateRight); return dateLeft.getFullYear() === dateRight.getFullYear(); } /** * @name isThisYear * @category Year Helpers * @summary Is the given date in the same year as the current date? * @pure false * * @description * Is the given date in the same year as the current date? * * > ⚠️ Please note that this function is not present in the FP submodule as * > it uses `Date.now()` internally hence impure and can't be safely curried. * * @param {Date|Number} date - the date to check * @returns {Boolean} the date is in this year * @throws {TypeError} 1 argument required * * @example * // If today is 25 September 2014, is 2 July 2014 in this year? * const result = isThisYear(new Date(2014, 6, 2)) * //=> true */ function isThisYear(dirtyDate) { requiredArgs(1, arguments); return isSameYear(dirtyDate, Date.now()); } /** * @name addDays * @category Day Helpers * @summary Add the specified number of days to the given date. * * @description * Add the specified number of days to the given date. * * @param {Date|Number} date - the date to be changed * @param {Number} amount - the amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. * @returns {Date} - the new date with the days added * @throws {TypeError} - 2 arguments required * * @example * // Add 10 days to 1 September 2014: * const result = addDays(new Date(2014, 8, 1), 10) * //=> Thu Sep 11 2014 00:00:00 */ function addDays(dirtyDate, dirtyAmount) { requiredArgs(2, arguments); var date = toDate(dirtyDate); var amount = toInteger(dirtyAmount); if (isNaN(amount)) { return new Date(NaN); } if (!amount) { // If 0 days, no-op to avoid changing times in the hour before end of DST return date; } date.setDate(date.getDate() + amount); return date; } /** * @name subDays * @category Day Helpers * @summary Subtract the specified number of days from the given date. * * @description * Subtract the specified number of days from the given date. * * @param {Date|Number} date - the date to be changed * @param {Number} amount - the amount of days to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. * @returns {Date} the new date with the days subtracted * @throws {TypeError} 2 arguments required * * @example * // Subtract 10 days from 1 September 2014: * const result = subDays(new Date(2014, 8, 1), 10) * //=> Fri Aug 22 2014 00:00:00 */ function subDays(dirtyDate, dirtyAmount) { requiredArgs(2, arguments); var amount = toInteger(dirtyAmount); return addDays(dirtyDate, -amount); } /** * @name isYesterday * @category Day Helpers * @summary Is the given date yesterday? * @pure false * * @description * Is the given date yesterday? * * > ⚠️ Please note that this function is not present in the FP submodule as * > it uses `Date.now()` internally hence impure and can't be safely curried. * * @param {Date|Number} date - the date to check * @returns {Boolean} the date is yesterday * @throws {TypeError} 1 argument required * * @example * // If today is 6 October 2014, is 5 October 14:00:00 yesterday? * const result = isYesterday(new Date(2014, 9, 5, 14, 0)) * //=> true */ function isYesterday(dirtyDate) { requiredArgs(1, arguments); return isSameDay(dirtyDate, subDays(Date.now(), 1)); } export { isYesterday as a, isThisYear as b, isToday as i }; //# sourceMappingURL=bundle-Br24ZBms.js.map