Documentation
¶
Index ¶
- Variables
- func NormalizeLanguage(language string) (string, error)
- func ParseFile[T any](fs fs.FS, fpath string, parse func(io.Reader, string) (T, error), target *T) error
- func SetChagOnly(cOpts *hebcal.CalOptions)
- func SetShiurim(cOpts *hebcal.CalOptions, shiurim []string) error
- func SetToday(cOpts *hebcal.CalOptions)
- type Config
- type Coordinates
Constants ¶
This section is empty.
Variables ¶
var Default = Config{
CandleLightingMins: 18,
NumYears: 1,
}
Default holds the default values for Config. It imitates hebcal.
var DefaultCity = "New York"
DefaultCity is the name of a city in the internal database, to be used in zmanim calculations if no location is otherwise configured.
var ErrUnreachable = errors.New("unreachable code")
ErrUnreachable means that there is a coding defect if returned.
Functions ¶
func NormalizeLanguage ¶ added in v0.0.2
NormalizeLanguage checks that `language` is equal to some known language under case folding, and returns the canonical form from locales.AllLocales. If language is empty, we return the default language `"en"`. If no valid value is recognized, we return an error.
func ParseFile ¶ added in v0.0.2
func ParseFile[T any]( fs fs.FS, fpath string, parse func(io.Reader, string) (T, error), target *T, ) error
ParseFile opens `fpath` from `fs`, calls `parse` on the file, and saves the result to `target`.
func SetChagOnly ¶ added in v0.0.2
func SetChagOnly(cOpts *hebcal.CalOptions)
SetChagOnly sets options on hebcal.CalOptions which hebcal itself would have set if the --chag-only flag were set on its CLI. This limits hebcal's output to days when melacha is prohibited.
func SetShiurim ¶ added in v0.0.2
func SetShiurim(cOpts *hebcal.CalOptions, shiurim []string) error
SetShiurim reads `shiurim` and sets the appropriate options on the hebcal.CalOptions.
Available shiurim values permitted in the list:
- `yerushalmi` `yerushalmi:vilna`
- `yerushalmi:schottenstein`
- `mishna-yomi`
- `daf-yomi`
- `nach-yomi`
func SetToday ¶ added in v0.0.2
func SetToday(cOpts *hebcal.CalOptions)
SetToday sets options on hebcal.CalOptions which hebcal itself would have set if the -T (--today) flag were set on its CLI, aside from what [(Config).SetDateRange] does already.
Types ¶
type Config ¶
type Config struct {
// ConfigSource names the file which produced this struct.
ConfigSource string `json:"-"`
// DateRange specifies the span of the calendrical data
// which hebcal should produce.
// This normally gets parsed from CLI arguments.
DateRange *daterange.DateRange `json:"-"`
// Now ensures that all parts of the calendar program
// have a consistent idea of the current time.
Now time.Time `json:"-"`
// FS controls where secondary files are loaded from.
// If replaced, it can allow access to internet-hosted files
// compiled-in resources, or stubbing out the default FS for testing.
// If nil, use [os.DirFS] starting from the current working directory.
FS fs.FS `json:"-"`
// Language sets the output language.
// Available options are in locales.AllLocales.
// Default: en
Language string `json:"language"`
// City sets geographical coordinates and a timezone for zmanim.
// Available options are in [zmanim.AllCities].
//
// If no such city is in the internal database, we will error
// unless `Geo` and `Timezone` are both set.
// If those are set, `City` will be used as the name for the city.
// Default: [DefaultCity]
City string `json:"city"`
// Geo specifies geographic coordinates for calculating zmanim.
// This may be left empty if a known City is specified or defaulted..
// If provided, a Timezone must also be set.
Geo *Coordinates `json:"geo"`
// Timezone is the name of a time zone in /usr/share/zoneinfo/
// (on typical POSIX systems).
// This may be left empty if a known City is specified or defaulted.
// If provided, Geo must also be set.
Timezone string `json:"timezone"`
// Shiurim lists daily learning schedules to be displayed.
// Avalable options:
//
// - `daf-yomi`
// - `mishna-yomi`
// - `nach-yomi`
// - `yerushalmi` (defaults to Vilna edition)
// - `yerushalmi:vilna`
// - `yerushalmi:schottenstein`
Shiurim []string `json:"shiurim"`
// Today makes the hebcal calendar functions only list information
// about today.
// Implies Omer, AddHebrewDates, and !IsHebrewYear.
Today bool `json:"today"`
// ChagOnly filters output events to only show holidays and their endings,
// during which melacha is prohibited.
// The event bitmask is set to
// CHAG | LIGHT_CANDLES | LIGHT_CANDLES_TZEIS | YOM_TOV_ENDS.
ChagOnly bool `json:"chag_only"`
// NoJulian disables the use of the Julian calendar for dates before 1752.
// I.e. use the proleptic Gregorian calendar before then,
// pretending that the Gregorian calendar existed
// before it was historically used.
NoJulian bool `json:"no_julian"`
// Hour24 makes TimedEvent.Render() return 24-hour time.
Hour24 bool `json:"hour24"`
// SunriseSunset adds sunrise and sunset events for every day.
SunriseSunset bool `json:"sunrise_sunset"`
// CandleLighting adds entries for candlelighting times.
CandleLighting bool `json:"candle_lighting"`
// DailyZmanim adds zmanim events for every day.
DailyZmanim bool `json:"daily_zmanim"`
// Molad adds a molad entry on Shabbat Mevorchim.
Molad bool `json:"molad"`
// WeeklyAbbreviated gives a weekly view.
// Omer, dafyomi, and non-date-specific zmanim are shown once a week,
// on the day of the week which corresponds to the first day in the range.
WeeklyAbbreviated bool `json:"weekly_abbreviated"`
// AddHebrewDates adds an entry for the Hebrew date for each day.
AddHebrewDates bool `json:"add_hebrew_dates"`
// AddHebrewDatesForEvents adds an entry for the Hebrew date
// on days with some event.
AddHebrewDatesForEvents bool `json:"add_hebrew_dates_for_events"`
// IsHebrewYear means to use Hebrew date ranges.
IsHebrewYear bool `json:"is_hebrew_year"`
// YomKippurKatan includes Yom Kippur Katan, a minor day of atonement
// occurring monthly on the day preceding each Rosh Chodesh.
YomKippurKatan bool `json:"yom_kippur_katan"`
// ShabbatMevarchim include Shabbat Mevarchim HaChodesh
// on the Shabbat before Rosh Chodesh.
ShabbatMevarchim bool `json:"shabbat_mevarchim"`
// NoHolidays suppresses default holidays.
NoHolidays bool `json:"no_holidays"`
// NoRoshChodesh suppresses Rosh Chodesh.
NoRoshChodesh bool `json:"no_rosh_chodesh"`
// IL uses the Israeli holiday and sedra schedule.
IL bool `json:"il"`
// NoModern suppresses modern holidays.
NoModern bool `json:"no_modern"`
// NoMinorFast suppresses minor fast days.
NoMinorFast bool `json:"no_minor_fast"`
// NoSpecialShabbat suppresses special Shabbatot.
NoSpecialShabbat bool `json:"no_special_shabbat"`
// Omer adds days of the Omer.
Omer bool `json:"omer"`
// Sedrot adds the weekly sedra on Saturdays.
Sedrot bool `json:"sedrot"`
// DailySedra adds the weekly sedra to every day.
DailySedra bool `json:"daily_sedra"`
// CandleLightingMins sets candle-lighting to occur
// this many minutes before sundown.
CandleLightingMins int `json:"candle_lighting_mins"`
// HavdalahMins sets havdalah to occur this many minutes after sundown.
HavdalahMins int `json:"havdalah_mins"`
// HavdalahDeg sets havdalah to occur when the sun is this many degrees
// below the horizon.
HavdalahDeg float64 `json:"havdalah_deg"`
// NumYears is how many years to generate events for.
// Default: 1
NumYears int `json:"num_years"`
// EventsFile is a file of user-defined events.
// Each line in the file has this format:
//
// MMMM DD Description
//
// where MMMM is a string identifying the Hebrew month
// and DD is a day number 1 through 30.
// Description is a newline-terminated string.
// Events are shown regardless of NoHolidays.
EventsFile string `json:"events_file"`
// YahrzeitsFile is a file of yartzeit dates.
// Each line is a death-date with this format:
//
// MM DD YYYY Description
//
// Where MM, DD and YYYY are the Gregorian date of death.
// Description is a newline-terminated string.
// Events are shown regardless of NoHolidays.
YahrzeitsFile string `json:"yahrzeits_file"`
}
Config defines the format of the config.json file. It also stores program values generated at runtime; these are annotated with `json:"-"` to distinguish them from other fields expected in the JSON.
func FromFile ¶
FromFile parses the file at `configPath` into a Config as JSON. It sets up the FS so that file references are interpreted relative to the configPath and must be local. This means that file references which fail filepath.IsLocal, i.e., leave the directory tree with abs paths or .., are not allowed. For the sake of debugging, it then populates `ConfigSource` with `configPath`. NOTE: This does not populate DateRange.
func FromReader ¶
FromReader parses an io.Reader into a Config as JSON. It does not set an FS. For the sake of debugging, it then populates `ConfigSource` with `configPath`.
func (Config) CalOptions ¶
func (c Config) CalOptions() (*hebcal.CalOptions, error)
CalOptions builds a hebcal.CalOptions from a Config. If FS is not set, the [DefaultFS] is used and file references are interpreted relative to the current working directory.
func (Config) Location ¶
Location builds data with which to calculate zmanim.
If `Geo` and `Timezone` are set and valid, we build a new zmanim.Location entry from them. Its `CountryCode` will be "IL" if `IL` is set, otherwise "ZZ". If `City` is also set, we use that as the name, otherwise we will use "User Defined City" like in hebcal.
If `City` is set and valid, we return its zmanim.Location entry. If `Timezone` is also set and valid, we override the timezone for that city with the one provided, and note the timezone modification as a suffix to its Name.
If no `Geo` or `City` is set, use the DefaultCity, like in hebcal.
The result of this method affects the output of hebcal functions when, e.g., `CandleLighting`, `SunriseSunset`, or `DailyZmanim` is set.
The following fields are read from the Config:
- `City`
- `Geo`
- `IL`
- `Timezone`
func (Config) Normalize ¶
Normalize returns a version of itself with canonicalized values.
# `Language` An error gets returned if the selected `Language` is unknown. Otherwise, it defaults the `Language` field if unset or lowercases it,
func (Config) SetDateRange ¶ added in v0.0.2
func (c Config) SetDateRange(cOpts *hebcal.CalOptions) error
SetDateRange validates the `DateRange` of the Config. If it is valid and consistent with the rest of the Config, it gets copied to the hebcal.CalOptions, along with other hebcal-like settings corresponding to the `DateRange`. If it is unset, a default is set on the hebcal.CalOptions, imitating hebcal.
It reads the following fields from the Config:
- `DateRange`
- `NoJulian`
- `Now`
- `NumYears`
- `Today`
type Coordinates ¶
Coordinates holds a latitude-longitude pair.
func (*Coordinates) Validate ¶
func (c *Coordinates) Validate() error
Validate returns an error if the `Lat` or `Lon` field is out of bounds, or if the Coordinates pair is nil.