# logseq-dateutils

> [:gift_heart: Sponsor this project on Github](https://github.com/sponsors/hkgnp) or [:coffee: Get me a coffee](https://www.buymeacoffee.com/hkgnp.dev) if you like this plugin!

Latest version **2.1.2** (published 2024-07-05) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install logseq-dateutils
pnpm add logseq-dateutils
yarn add logseq-dateutils
bun add logseq-dateutils
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2024-07-05 |
| First published | 2022-01-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 1 |
| Unpacked size | 19.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | hkgnp |
| Maintainers | hkgnp |
| Keywords | logseq, scheduled, deadline, date, utilities |

## Links

- npm: https://www.npmjs.com/package/logseq-dateutils
- Repository: https://github.com/hkgnp/logseq-dateutils
- Homepage: https://github.com/hkgnp/logseq-dateutils#readme
- Issues: https://github.com/hkgnp/logseq-dateutils/issues
- npm.io page: https://npm.io/package/logseq-dateutils

## Dependencies (1)

- [date-fns](https://npm.io/package/date-fns.md) ^2.30.0

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 2.1.2 (latest) — 2024-07-05
- 2.1.1 — 2023-10-03
- 2.1.0 — 2023-10-03
- 2.0.0 — 2023-10-03
- 0.0.27 — 2023-10-03
- 0.0.26 — 2022-11-05
- 0.0.25 — 2022-11-05
- 0.0.24 — 2022-11-05
- 0.0.23 — 2022-11-05
- 0.0.22 — 2022-06-22
- 0.0.21 — 2022-04-23
- 0.0.20 — 2022-03-16
- 0.0.19 — 2022-03-12
- 0.0.18 — 2022-03-12
- 0.0.17 — 2022-03-12
- … 16 more at https://npm.io/package/logseq-dateutils/versions

## README

[:gift_heart: Sponsor this project on Github](https://github.com/sponsors/hkgnp) or [:coffee: Get me a coffee](https://www.buymeacoffee.com/hkgnp.dev) if you like this plugin!

# Overview

Provides some date utilities for developing Logseq plugins, in particular to cater to handling multiple user-defined date formats.

# Installation

With npm:

```
npm i logseq-dateutils
```

Import (you may also import only selective functions for your needs):

```
import { getDateForPage, getDateForPageWithoutBrackets, getDayInText, getScheduledDeadlineDateDay, getScheduledDeadlineDateDayTime } from 'logseq-dateutils';
```

# Usage

Below is an elaboration of the methods available:

## getDateForPage or getDateForPageWithoutBrackets

Returns the specified date based on the user's preferred date format. Accepts 2 arguments. `getDateForPage` returns the date with brackets (`[[date]]`) while `getDateForPageWithoutBrackets` returns the date without the brackets.

```
import { getDateForPage, getDateForPageWithoutBrackets, getDayInText, getScheduledDeadlineDate } from 'logseq-dateutils';

const preferredDateFormat = 'yyyy/MM/dd';
const today = new Date();

const todayDateInUserFormat = getDateForPage(today, preferredDateFormat);
console.log(todayDateInUserFormat);
```

## getDayInText

Returns the day, based on the specified date.

```
const today = new Date();

const todayDay = getDayInText(today);
```

## getScheduledDeadlineDateDay

Returns the date format that is needed (without the time) if your plugin requires creation of `SCHEDULED` or `DEADLINE` items.

```
const today = new Date();

await logseq.Editor.updateBlock(uuid, `A quick brown fox
SCHEDULED: <getScheduledDeadlineFormat(today)>`)
```

## getScheduledDeadlineDateDayTime

Returns the date format that is needed (including the time) if your plugin requires creation of `SCHEDULED` or `DEADLINE` items.

```
const today = new Date();

await logseq.Editor.updateBlock(uuid, `A quick brown fox
DEADLINE: <getScheduledDeadlineDateDayTime(today)>`)
```

# Getting Help

Do join [Logseq's Discord](https://discord.gg/KpN4eHY) and look for me there!

---
_Source: https://npm.io/package/logseq-dateutils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
