date-fns#isEqual TypeScript Examples

The following examples show how to use date-fns#isEqual. 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: FakeAppointmentsRepository.ts    From gobarber-api with MIT License 6 votes vote down vote up
public async findByDate({
    date,
    provider_id,
  }: IFindByDateDTO): Promise<Appointment | undefined> {
    const findAppointment = this.appointments.find(
      appointment =>
        isEqual(appointment.date, date) &&
        appointment.provider_id === provider_id,
    );

    return findAppointment;
  }
Example #2
Source File: GraphUtils.ts    From cashcash-desktop with MIT License 6 votes vote down vote up
static reduceByAddingBorderValue(
        splitList: GraphSplit[],
        fromDate: Date,
        toDate: Date,
    ): GraphSplit[] {
        if (toDate && !isEqual(splitList[0].transactionDate, toDate)) {
            const toSplit: GraphSplit = {
                ...splitList[0],
                transactionDate: toDate,
            };
            splitList = [toSplit, ...splitList];
        }
        if (fromDate && !isEqual(splitList[splitList.length - 1].transactionDate, fromDate)) {
            const fromSplit: GraphSplit = {
                ...splitList[splitList.length - 1],
                transactionDate: fromDate,
            };
            splitList = [...splitList, fromSplit];
        }

        return splitList;
    }
Example #3
Source File: dateFormat.ts    From apps with GNU Affero General Public License v3.0 6 votes vote down vote up
isDateOnlyEqual = (left: Date, right: Date): boolean => {
  const formattedLeft = new Date(
    left.getFullYear(),
    left.getMonth(),
    left.getDate(),
  );
  const formattedRight = new Date(
    right.getFullYear(),
    right.getMonth(),
    right.getDate(),
  );

  return isEqual(formattedLeft, formattedRight);
}
Example #4
Source File: FakeAppointmentsRepository.ts    From gobarber-project with MIT License 6 votes vote down vote up
public async findByDate(
    date: Date,
    provider_id: string,
  ): Promise<Appointment | undefined> {
    const findAppointment = this.appointments.find(
      appointment =>
        isEqual(appointment.date, date) &&
        appointment.provider_id === provider_id,
    );

    return findAppointment;
  }
Example #5
Source File: FakeAppointmentsRepository.ts    From GoBarber with MIT License 6 votes vote down vote up
public async findByDate(
    date: Date,
    provider_id: string,
  ): Promise<Appointment | undefined> {
    const findAppointment = this.appointments.find(
      appointment =>
        isEqual(appointment.date, date) &&
        appointment.provider_id === provider_id,
    );

    return findAppointment;
  }
Example #6
Source File: FakeAppointmentsRepository.ts    From hotseat-api with MIT License 5 votes vote down vote up
public async findByDate(date: Date): Promise<Appointment | undefined> {
    const foundAppointment = this.appointments.find(appointment =>
      isEqual(appointment.date, date),
    );

    return foundAppointment;
  }
Example #7
Source File: DateRangePicker.stories.tsx    From gio-design with Apache License 2.0 5 votes vote down vote up
StaticDisabledDate: Story<StaticDateRangePickerProps> = () => {
  const disabledDate = (date: Date) => isEqual(startOfWeek(date), startOfDay(date))
  return <DateRangePicker.Static
    disabledDate={disabledDate}
  />
}
Example #8
Source File: validator.ts    From elements with MIT License 5 votes vote down vote up
private validateMinSingle = (value: string): boolean => {
    const parsedDate: Date = this.parseDate(value);
    return (
      isEqual(parsedDate, this._minDate) || isAfter(parsedDate, this._minDate)
    );
  };
Example #9
Source File: validator.ts    From elements with MIT License 5 votes vote down vote up
private validateMaxSingle = (value: string): boolean => {
    const parsedDate: Date = this.parseDate(value);
    return (
      isEqual(parsedDate, this._maxDate) || isBefore(parsedDate, this._maxDate)
    );
  };
Example #10
Source File: akashSync.ts    From akashlytics with GNU General Public License v3.0 4 votes vote down vote up
async function insertBlocks(startHeight, endHeight) {
  const blockCount = endHeight - startHeight + 1;
  console.log("Inserting " + blockCount + " blocks into database");
  syncingStatus = "Inserting blocks";

  let lastInsertedBlock = (await Block.findOne({
    include: [
      {
        model: Day,
        required: true
      }
    ],
    order: [["height", "DESC"]]
  })) as any;

  let blocksToAdd = [];
  let txsToAdd = [];
  let msgsToAdd = [];

  for (let i = startHeight; i <= endHeight; ++i) {
    syncingStatus = `Inserting block #${i} / ${endHeight}`;

    const blockData = await getCachedBlockByHeight(i);

    if (!blockData) throw "Block # " + i + " was not in cache";

    let msgIndexInBlock = 0;
    const blockDatetime = new Date(blockData.block.header.time);

    const txs = blockData.block.data.txs;
    for (let txIndex = 0; txIndex < txs.length; ++txIndex) {
      const tx = txs[txIndex];
      const hash = sha256(Buffer.from(tx, "base64")).toUpperCase();
      const txId = uuid.v4();

      let hasInterestingTypes = false;
      const decodedTx = decodeTxRaw(fromBase64(tx));
      const msgs = decodedTx.body.messages;

      for (let msgIndex = 0; msgIndex < msgs.length; ++msgIndex) {
        const msg = msgs[msgIndex];
        const isInterestingType = Object.keys(messageHandlers).includes(msg.typeUrl);

        msgsToAdd.push({
          id: uuid.v4(),
          txId: txId,
          type: msg.typeUrl,
          typeCategory: msg.typeUrl.split(".")[0].substring(1),
          index: msgIndex,
          height: i,
          indexInBlock: msgIndexInBlock++,
          isInterestingType: isInterestingType
        });

        if (isInterestingType) {
          hasInterestingTypes = true;
        }
      }

      txsToAdd.push({
        id: txId,
        hash: hash,
        height: i,
        index: txIndex,
        hasInterestingTypes: hasInterestingTypes
      });
    }

    const blockEntry = {
      height: i,
      datetime: new Date(blockData.block.header.time),
      totalTxCount: (lastInsertedBlock?.totalTxCount || 0) + txs.length,
      dayId: lastInsertedBlock?.dayId,
      day: lastInsertedBlock?.day
    };

    const blockDate = new Date(Date.UTC(blockDatetime.getUTCFullYear(), blockDatetime.getUTCMonth(), blockDatetime.getUTCDate()));

    if (!lastInsertedBlock || !isEqual(blockDate, lastInsertedBlock.day.date)) {
      console.log("Creating day: ", blockDate, i);
      const newDay = await Day.create({
        id: uuid.v4(),
        date: blockDate,
        firstBlockHeight: i,
        lastBlockHeightYet: i
      });

      blockEntry.dayId = newDay.id;
      blockEntry.day = newDay;

      if (lastInsertedBlock) {
        lastInsertedBlock.day.lastBlockHeight = lastInsertedBlock.height;
        lastInsertedBlock.day.lastBlockHeightYet = lastInsertedBlock.height;
        await lastInsertedBlock.day.save();
      }
    }
    lastInsertedBlock = blockEntry;

    blocksToAdd.push(blockEntry);

    if (blocksToAdd.length >= 1_000 || i === endHeight) {
      await Block.bulkCreate(blocksToAdd);
      await Transaction.bulkCreate(txsToAdd);
      await Message.bulkCreate(msgsToAdd);

      blocksToAdd = [];
      txsToAdd = [];
      msgsToAdd = [];
      console.log(`Blocks added to db: ${i - startHeight + 1} / ${blockCount} (${(((i - startHeight + 1) * 100) / blockCount).toFixed(2)}%)`);

      if (lastInsertedBlock) {
        lastInsertedBlock.day.lastBlockHeightYet = lastInsertedBlock.height;
        await lastInsertedBlock.day.save();
      }
    }
  }

  let totalBlockCount = await Block.count();
  let totalTxCount = await Transaction.count();
  let totalMsgCount = await Message.count();

  console.log("Total: ");
  console.table([{ totalBlockCount, totalTxCount, totalMsgCount }]);
}