Things will break, and APIs might change. Be cautious using this in production. Additionally, not all methods have been tested for accuracy.
Kosher Zmanim is a TS/JS port of the KosherJava library.
NPM:
npm install kosher-zmanim
UMD (browser):
<script src="https://unpkg.com/kosher-zmanim/dist/kosher-zmanim.min.js"></script>
It is highly recommended that you pin the version (e.g. https://unpkg.com/kosher-zmanim@0.6.0/dist/kosher-zmanim.min.js
),
so updates don't break your app.
ES6 modules / Typescript:
import * as KosherZmanim from "kosher-zmanim";
Or:
import { ComplexZmanimCalendar, getZmanimJson } from "kosher-zmanim";
CommonJS modules:
const KosherZmanim = require("kosher-zmanim");
Or:
const { ComplexZmanimCalendar, getZmanimJson } = require("kosher-zmanim");
UMD (browser):
For UMD, a global KosherZmanim
object is exposed.
The KosherJava library has been ported to JS, following the original API as close as possible. The classes are exposed as named exports. You can instantiate or extend those classes as necessary, the same way you would in Java.
const zmanimCalendar = new KosherZmanim.ZmanimCalendar();
See the KosherJava API documentation for more details.
Alternatively, there is a getZmanimJson()
utility method.
const zmanim = KosherZmanim.getZmanimJson(options);
Check out the demo, and look at the code to see an example of how it's used.
The options
object has the following structure and defaults:
{
date: Date | string | number = new Date(),
timeZoneId: string
locationName?: string,
latitude: number,
longitude: number,
elevation?: number = 0,
complexZmanim?: boolean = false,
}
This library uses Luxon as a date/time library, since
Javascript's Date
object does not support setting timezones other than the system timezone.
All class methods that return a DateTime
object will be in UTC.
AstronomicalCalendar.getTemporalHour()
returnsnull
instead ofLong.MIN_VALUE
if the calculations cannot be completed.- JS/TS does not have a parallel to Java's
Long.MIN_VALUE
, soLong_MIN_VALUE
is set toNaN
. - The following methods are not supported:
AstronomicalCalendar.toString()
AstronomicalCalendar.toJSON()
(UseZmanimFormatter.toJSON(astronomicalCalendar)
instead).AstronomicalCalculator.getDefault()
(Usenew NOAACalculator()
instead).JewishCalendar.getDafYomiBavli()
(UseYomiCalculator.getDafYomiBavli(jewishCalendar)
instead).JewishCalendar.getDafYomiYerushalmi()
(UseYerushalmiYomiCalculator.getDafYomiYerushalmi(jewishCalendar)
instead).Time.toString()
(Usenew ZmanimFormatter(TimeZone.getTimeZone("UTC")).format(time)
instead).ZmanimFormatter.toXML()
- Some method signatures are different, due to the differences between Java and JS.
- The
Zman
class uses public members instead of getters and setters.