date-fns#isDate JavaScript Examples

The following examples show how to use date-fns#isDate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DateTime.js    From rate-repository-api with MIT License 5 votes vote down vote up
isValidDateTime = value => {
  const isSerializable =
    isDate(value) || typeof value === 'string' || typeof value === 'number';

  return isSerializable ? isValid(new Date(value)) : false;
}
Example #2
Source File: init.client.js    From audiobookshelf with GNU General Public License v3.0 5 votes vote down vote up
Vue.prototype.$formatJsDate = (jsdate, fnsFormat = 'MM/dd/yyyy HH:mm') => {
  if (!jsdate || !isDate(jsdate)) return ''
  return format(jsdate, fnsFormat)
}
Example #3
Source File: init.client.js    From audiobookshelf with GNU General Public License v3.0 5 votes vote down vote up
Vue.prototype.$addDaysToToday = (daysToAdd) => {
  var date = addDays(new Date(), daysToAdd)
  if (!date || !isDate(date)) return null
  return date
}
Example #4
Source File: init.client.js    From audiobookshelf with GNU General Public License v3.0 5 votes vote down vote up
Vue.prototype.$addDaysToDate = (jsdate, daysToAdd) => {
  var date = addDays(jsdate, daysToAdd)
  if (!date || !isDate(date)) return null
  return date
}
Example #5
Source File: Single.jsx    From airdrop with MIT License 4 votes vote down vote up
Single = ({
  data,
  user,
  update,
  hashTable,
  userStatus,
  TypingIndication,
  uid,
  Count,
  lastMessage,
  sidebar,
}) => {
  const { id } = useParams();

  return (
    data &&
    data.map((snapShot, i, arr) => {
      const cond = arr.length === i + 1;
      let messagecount = 0;
      let size = 0;
      if (snapShot === undefined) return '';
      const hash = hashTable.includes(snapShot.slug);
      if (snapShot.generated === false && snapShot.from === user.uid && !hash) {
        const e2e = new E2E();
        e2e
          .setPrivateKey(
            snapShot.slug,
            snapShot.channelId,
            snapShot.bobPublicKey,
          )
          .then(() => {
            update({ id: snapShot.channelId, slug: snapShot.slug });
          })
          .catch((err) => {
            console.log(err);
          });
      }
      let status = {
        status: 'Offline',
        LastSeen: null,
      };

      if (userStatus.has(snapShot.pro.data().uid)) {
        status = userStatus.get(snapShot.pro.data().uid).status;
      }

      size = Count.size;

      if (Count.has(snapShot.channelId)) {
        messagecount = Count.get(snapShot.channelId).messageCount;
      }

      if (size > 0 && 'setAppBadge' in navigator) {
        navigator.setAppBadge(size).catch((error) => {
          console.log('error:', error);
        });
      }

      let lastMessagetime = null;
      const hasLastMessage = lastMessage.has(snapShot.channelId);

      if (hasLastMessage) {
        const message = lastMessage.get(snapShot.channelId);
        lastMessagetime = message.message?.time;
      }

      const isdate = isDate(new Date(lastMessagetime));
      const date = new Date(lastMessagetime);

      const checkDate =
        lastMessagetime !== undefined && isdate && date !== 'Invalid Date';

      return (
        <Link
          to={`/r/${snapShot.channelId}/${
            snapShot.from === uid ? '#init' : ''
          }`}
          key={snapShot.channelId}
        >
          {size > 0 ? (
            <Helmet>
              <title>{`(${size}) Relp`}</title>
            </Helmet>
          ) : (
            <Helmet>
              <title>Relp</title>
            </Helmet>
          )}
          <div
            className={`grid ${
              Styles.grid7
            } gap-1 cursor-pointer pr-4 hover:bg-dark focus:bg-primary ${
              id === snapShot.channelId && 'bg-dark'
            }
            `}
          >
            <div className="px-3 flex items-center ">
              <div className="bg-secondary rounded-full relative">
                <img
                  src={snapShot.pro.data().photoURL}
                  className="rounded-full "
                  alt="Yourfile"
                  draggable="false"
                />
                {status?.status.includes('Online') && (
                  <div
                    style={{
                      width: '13px',
                      height: '13px',
                      border: '2px solid #000',
                    }}
                    title="Online"
                    className="rounded-full absolute bottom-0 right-0 bg-accent"
                  />
                )}
              </div>
            </div>
            <div
              style={{
                whiteSpace: 'nowrap',
                overflow: 'hidden',
                textOverflow: 'ellipsis',
              }}
              className={`w-auto font-sans flex flex-col py-3 justify-between ${
                !cond && Styles.borderBorder
              }`}
            >
              <div
                className={`text-white text-lg ${Styles.overFLow} flex justify-between`}
              >
                <div className={Styles.overFLow}>
                  <span>{snapShot.pro.data().isAnonymous && '~ '}</span>
                  <span>{snapShot.pro.data().displayName}</span>
                </div>
                <div className={`${Styles.gray1} text-xs`}>
                  {(hasLastMessage &&
                    checkDate &&
                    isdate &&
                    ConversationTime(new Date(lastMessagetime))) ||
                    ''}
                </div>
              </div>
              <div
                style={{
                  fontSize: '14px',
                }}
                className={Styles.gray1}
              >
                <Utils
                  snapShot={snapShot}
                  TypingIndication={TypingIndication}
                  status={status}
                  count={messagecount}
                  lastMessage={lastMessage}
                  hasLastMessage={hasLastMessage}
                />
              </div>
            </div>
          </div>
        </Link>
      );
    })
  );
}