dayphase
Version:
Determines the dayphase based on hour boundaries. It allows flexible time segmentation for different cultural or system-defined day phases.
56 lines (34 loc) • 1.95 kB
Markdown
# dayphase
> **Archetype:** Node.js package
**dayphase** determines the dayphase based on hour boundaries. It allows flexible time segmentation for different cultural or system-defined day phases.
## Install
```sh
npm install dayphase
```
## Usage
```js
import dayphase from 'dayphase';
console.log(dayphase([4, 17, 21], 6)); // ➝ 1 (Day Phase)
console.log(dayphase([4, 17, 21], 18)); // ➝ 2 (Evening Phase)
console.log(dayphase([4, 17, 21], 22)); // ➝ 0 (Night Phase)
console.log(dayphase([4, 17, 21], 2)); // ➝ 0 (Night Phase, before first phase)
```
## API
### `dayphase(phases: number[], hour?: number): number`
#### Parameters
| Parameter | Type | Description |
| --------- | ---------- | ------------------------------------------------------------------------- |
| `phases` | `number[]` | (Required) Ordered array of hour values (0-24) defining phase boundaries. |
| `hour` | `number` | (Optional) Hour of the day (0-24). Defaults to `new Date().getHours()`. |
#### Returns
| Type | Description |
| -------- | ---------------------------------------------------------------- |
| `number` | The index of the current time phase based on the `phases` array. |
## Related Link
This package is part of my **highsociety** meta suite:
[https://github.com/alexstevovich/highsociety-node](https://github.com/alexstevovich/highsociety-node) - Prose, linguistic, time, and cultural string formatting.
[https://github.com/alexstevovich/wellwish-node](https://github.com/alexstevovich/wellwish-node) - Outputs a nuanced well-wishing phrase based on English cultural norms.
### Development Homepage
[https://github.com/alexstevovich/dayphase-node](https://github.com/alexstevovich/dayphase-node)
## License
Licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).