Exemple #1
0
func getZmanimString(c appengine.Context, zipcode string) string {
	if len(zipcode) == 0 {
		return ""
	}
	if zipMap == nil {
		err := loadZipMap(c)
		if err != nil {
			return ""
		}
	}

	zd, ok := zipMap[zipcode]
	if !ok {
		return ""
	}

	utc := time.Now()
	local, _ := timezone.TimeInZone(&utc, zd.Timezone, zd.DST)

	z := zmanim.Zmanim{
		Time: local,
		Geolocation: zmanim.Geolocation{
			Longitude: zd.Longitude,
			Latitude:  zd.Latitude,
		},
	}

	zenith := zmanim.GeometricZenith

	rise := z.GetUtcSunrise(zenith, false)
	sunrise := z.GetDateFromTime(rise)

	set := z.GetUtcSunset(zenith, false)
	sunset := z.GetDateFromTime(set)

	tzais := z.GetTzais()

	dateFormat := "3:04:05PM"

	s := ""

	s += fmt.Sprintf("Zmanim for %v, %v (%v) on %v\n",
		zd.City, zd.State, zipcode, z.Time.Format("1/2/2006"))

	s += fmt.Sprintf("Sunrise: %v\n", sunrise.Format(dateFormat))
	s += fmt.Sprintf("Sunset:  %v\n", sunset.Format(dateFormat))
	s += fmt.Sprintf("Tzais:   %v\n", tzais.Format(dateFormat))

	return s
}
Exemple #2
0
func handlePostZmanim(w http.ResponseWriter, r *http.Request) {

	zipcode := r.FormValue("zipcode")

	if zipcode == "" {
		fmt.Fprintf(w, "Empty zipcode specified")
		return
	}

	zd, ok := zipMap[zipcode]
	if !ok {
		fmt.Fprintf(w, "zipcode \"%v\" is not in the database\n", zipcode)
		return
	}

	utc := time.Now()
	local, _ := timezone.TimeInZone(&utc, zd.Timezone, zd.DST)

	z := zmanim.Zmanim{
		Time: local,
		Geolocation: zmanim.Geolocation{
			Longitude: zd.Longitude,
			Latitude:  zd.Latitude,
		},
	}

	zenith := zmanim.GeometricZenith

	rise := z.GetUtcSunrise(zenith, false)
	sunrise := z.GetDateFromTime(rise)

	set := z.GetUtcSunset(zenith, false)
	sunset := z.GetDateFromTime(set)

	tzais := z.GetTzais()

	dateFormat := "1/2/2006 3:04:05PM (MST)"

	fmt.Fprintf(w, "<html><body>")

	fmt.Fprintf(w, "Zmanim for %v, %v (%v) on %v <br>",
		zd.City, zd.State, zipcode, z.Time.Format("1/2/2006"))

	//fmt.Fprintf(w, "(Timezone Offset: %v DST? %v)<br>", zd.Timezone, zd.DST == 1)

	fmt.Fprintf(w, "<table>")

	fmt.Fprintf(w, "<tr>")
	fmt.Fprintf(w, "<td>")
	fmt.Fprintf(w, "Sunrise:")
	fmt.Fprintf(w, "</td>")
	fmt.Fprintf(w, "<td>")
	fmt.Fprintf(w, "%v", sunrise.Format(dateFormat))
	fmt.Fprintf(w, "</td>")
	fmt.Fprintf(w, "</tr>")

	fmt.Fprintf(w, "<tr>")
	fmt.Fprintf(w, "<td>")
	fmt.Fprintf(w, "Sunset:")
	fmt.Fprintf(w, "</td>")
	fmt.Fprintf(w, "<td>")
	fmt.Fprintf(w, "%v", sunset.Format(dateFormat))
	fmt.Fprintf(w, "</td>")
	fmt.Fprintf(w, "</tr>")

	fmt.Fprintf(w, "<tr>")
	fmt.Fprintf(w, "<td>")
	fmt.Fprintf(w, "Tzais:")
	fmt.Fprintf(w, "</td>")
	fmt.Fprintf(w, "<td>")
	fmt.Fprintf(w, "%v", tzais.Format(dateFormat))
	fmt.Fprintf(w, "</td>")
	fmt.Fprintf(w, "</tr>")

	fmt.Fprintf(w, "</table>")

	fmt.Fprintf(w, "</body></html>")
}