1.0.1 • Published 4 months ago

dayphase v1.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

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

npm install dayphase

Usage

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

ParameterTypeDescription
phasesnumber[](Required) Ordered array of hour values (0-24) defining phase boundaries.
hournumber(Optional) Hour of the day (0-24). Defaults to new Date().getHours().

Returns

TypeDescription
numberThe 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 - Prose, linguistic, time, and cultural string formatting.

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

License

Licensed under the Apache License 2.0.