caleb

package module
v0.0.0-...-ad5727c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2018 License: MIT Imports: 3 Imported by: 0

README

caleb

Jewish dates conversion tool

Usage:

go get github.com/simolev/caleb

package main

import (
      "fmt"
      "github.com/simolev/caleb"
      "time"
)

func main() {
      j1 := caleb.JewishDate{Shana: 5779, Chodesh: 7, Yom: 25} // 25 Adar II 5779
      g1 := caleb.JewishToGregorian(j1)                        //
      fmt.Println(j1, "=>", g1.Format("2006-01-02"))           // 25 Adar II 5779 => 2019-04-01
      g2 := time.Date(2018, 8, 11, 0, 0, 0, 0, time.UTC)       // 2018-08-11
      j2 := caleb.GregorianToJewish(g2)                        //
      fmt.Println(g2.Format("2006-01-02"), "=>", j2)           // 2018-08-11 => 30 Av 5778
}
Disclaimer:

a) It is not accurate for dates before Gregorian 1582-10-15. In the Gregorian calendar, there are 10 missing days between 1582-10-15 and 1582-10-04. Those days never occurred, but nonetheless they seem to exist in go's implementation, and the only solution I see at the moment would be to add manual correction to the algorithm.

b) This is quite new and would require more thorough testing before being relied upon.

c) Code could be more idiomatic and optimized.

Credits:

Thanks to info@dafaweek.com.
Converted from javascript: http://www.dafaweek.com/HebCal/HebCalSampleSource.php
See also http://www.dafaweek.com/hebcal/hebcalvb6.php

Documentation

Overview

Package caleb provides a JewishDate type and conversion to and from time.Time

package main

import (
  "fmt"
  "github.com/simolev/caleb"
  "time"
)

func main() {
  j1 := caleb.JewishDate{Shana: 5779, Chodesh: 7, Yom: 25} // 25 Adar II 5779
  g1 := caleb.JewishToGregorian(j1)                        //
  fmt.Println(j1, "=>", g1.Format("2006-01-02"))           // 25 Adar II 5779 => 2019-04-01
  g2 := time.Date(2018, 8, 11, 0, 0, 0, 0, time.UTC)       // 2018-08-11
  j2 := caleb.GregorianToJewish(g2)                        //
  fmt.Println(g2.Format("2006-01-02"), "=>", j2)           // 2018-08-11 => 30 Av 5778
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DaysInShana

func DaysInShana(shana int) int

DaysInShana return the number of days in the passed shana.

func IsMehubberet

func IsMehubberet(shana int) (mehubberet bool)

Shana Mehubberet has 13 months instead of 12 and occurs on years 3, 6, 8, 11, 14, 17, 19 of a 19 year cycle.

func JewishToGregorian

func JewishToGregorian(j JewishDate) (gregorian time.Time)

JewishToGregorian accepts a JewishDate struct and returns the corresponding gregorian date in time.Time format. Only the date part is relevant, time will be 0 and timezone UTC.

func MonthsSinceFirstMolad

func MonthsSinceFirstMolad(shana int) (n int)

MonthsSinceFirstMolad returns the number of months since the very first Molad until the beginning of the passed shana.

func RoshHashana

func RoshHashana(shana int) (roshHashana time.Time)

RoshHashana returns the gregorian day for Rosh Hashana (1st of Tishri) of the passed shana.

func SameDate

func SameDate(d1, d2 time.Time) bool

SameDate checks whether the date part of two time.Time objects is the same; time and timezone are not taken into account.

Types

type JewishDate

type JewishDate struct {
	Shana   int
	Chodesh int
	Yom     int
}

func GregorianToJewish

func GregorianToJewish(dGreg time.Time) JewishDate

GregorianToJewish accepts a gregorian date in time.Time format and returns a JewishDate struct. Only the date part is relevant, time and timezone are discarded.

func (JewishDate) Serialize

func (t JewishDate) Serialize() (Shana int, Chodesh int, Yom int)

Serialize returns the components Shana, Chodesh, Yom.

func (JewishDate) Short

func (t JewishDate) Short() string

Short returns a numerical representation of the Jewish date: 5779-07-25.

func (JewishDate) String

func (t JewishDate) String() string

String returns a representation of the Jewish date where the month is spelled out: 25 Adar II 5779.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL