Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/MoonGlobals.py
diff options
context:
space:
mode:
Diffstat (limited to 'MoonGlobals.py')
-rw-r--r--MoonGlobals.py308
1 files changed, 159 insertions, 149 deletions
diff --git a/MoonGlobals.py b/MoonGlobals.py
index 3096b18..0122fc5 100644
--- a/MoonGlobals.py
+++ b/MoonGlobals.py
@@ -86,7 +86,7 @@ new_moon_array = ("2008-01-08 11:37_", "2008-02-07 03:44A", "2008-03-07 17:14_",
"2015-01-20 13:14_", "2015-02-18 23:47_", "2015-03-20 09:36T", "2015-04-18 18:57_",
"2015-05-18 04:13_", "2015-06-16 14:05_", "2015-07-16 01:24_", "2015-08-14 14:54_",
"2015-09-13 06:41P", "2015-10-13 00:06_", "2015-11-11 17:47_", "2015-12-11 10:29_",
-
+
"2016-01-10 01:30_", "2016-02-08 14:39_", "2016-03-09 01:54T", "2016-04-07 11:24_",
"2016-05-06 19:30_", "2016-06-05 03:00_", "2016-07-04 11:01_", "2016-08-02 20:45_",
"2016-09-01 09:03A", "2016-10-01 00:12_", "2016-10-30 17:38_", "2016-11-29 12:18_",
@@ -251,179 +251,189 @@ last_quarter_array = ("2008-01-30 05:03", "2008-02-29 02:18", "2008-03-29 21:47"
"2018-12-29 09:34")
def next_full_moon_sec_at_time(now):
- # Return seconds to the next Full Moon.
- for date_string in full_moon_array:
- next = time.mktime(time.strptime(date_string[:-1], format))
- if next >= now:
- break
- return next - now
+ # Return seconds to the next Full Moon.
+ for date_string in full_moon_array:
+ next = time.mktime(time.strptime(date_string[:-1], format))
+ if next >= now:
+ break
+ return next - now
def next_new_moon_sec_at_time(now):
- # Return seconds to the next New Moon.
- for date_string in new_moon_array:
- next = time.mktime(time.strptime(date_string[:-1], format))
- if next >= now:
- break
- return next - now
+ # Return seconds to the next New Moon.
+ for date_string in new_moon_array:
+ next = time.mktime(time.strptime(date_string[:-1], format))
+ if next >= now:
+ break
+ return next - now
def next_quarter_moon_sec_at_time(now):
- # Return seconds to the next Quater Moon phase (could be First or Last).
- for date_string in first_quarter_array:
- next1 = time.mktime(time.strptime(date_string, format))
- if next1 >= now:
- break
- for date_string in last_quarter_array:
- next2 = time.mktime(time.strptime(date_string, format))
- if next2 >= now:
- break
- next = min(next1, next2)
- return next - now
+ # Return seconds to the next Quater Moon phase (could be First or Last).
+ for date_string in first_quarter_array:
+ next1 = time.mktime(time.strptime(date_string, format))
+ if next1 >= now:
+ break
+ for date_string in last_quarter_array:
+ next2 = time.mktime(time.strptime(date_string, format))
+ if next2 >= now:
+ break
+ next = min(next1, next2)
+ return next - now
def last_full_moon_sec_at_time(now):
- # Return (positive) seconds since the last Full Moon.
- for date_string in full_moon_array:
- then = time.mktime(time.strptime(date_string[:-1], format))
- if then >= now:
- break
- last = then
- return now - last
+ # Return (positive) seconds since the last Full Moon.
+ for date_string in full_moon_array:
+ then = time.mktime(time.strptime(date_string[:-1], format))
+ if then >= now:
+ break
+ last = then
+ return now - last
def last_new_moon_sec_at_time(now):
- # Return (positive) seconds since the last New Moon.
- for date_string in new_moon_array:
- then = time.mktime(time.strptime(date_string[:-1], format))
- if then >= now:
- break
- last = then
- return now - last
+ # Return (positive) seconds since the last New Moon.
+ for date_string in new_moon_array:
+ then = time.mktime(time.strptime(date_string[:-1], format))
+ if then >= now:
+ break
+ last = then
+ return now - last
def last_quarter_moon_sec_at_time(now):
- # Return (positive) seconds to the last Quater Moon phase (could be First or Last).
- for date_string in first_quarter_array:
- then = time.mktime(time.strptime(date_string, format))
- if then >= now:
- break
- last1 = then
- for date_string in last_quarter_array:
- then = time.mktime(time.strptime(date_string, format))
- if then >= now:
- break
- last2 = then
- last = max(last1, last2)
- return now - last
+ # Return (positive) seconds to the last Quater Moon phase (could be First or Last).
+ for date_string in first_quarter_array:
+ then = time.mktime(time.strptime(date_string, format))
+ if then >= now:
+ break
+ last1 = then
+ for date_string in last_quarter_array:
+ then = time.mktime(time.strptime(date_string, format))
+ if then >= now:
+ break
+ last2 = then
+ last = max(last1, last2)
+ return now - last
def lunation_at_time(now):
- # Return lunation number, 0 started on Dec 18, 1922, current data set starts as 2008
- lunation = 1051
- for date_string in new_moon_array:
- next = time.mktime(time.strptime(date_string[:-1], format))
- if next >= now:
- break
- lunation += 1
- return lunation
+ # Return lunation number, 0 started on Dec 18, 1922, current data set starts as 2008
+ lunation = 1051
+ for date_string in new_moon_array:
+ next = time.mktime(time.strptime(date_string[:-1], format))
+ if next >= now:
+ break
+ lunation += 1
+ return lunation
def next_lunar_eclipse_sec_at_time(now):
- # Return (positive) seconds to the next Lunar eclipe or -1.
- for date_string in full_moon_array:
- if date_string[-1:] != "_":
- next = time.mktime(time.strptime(date_string[:-1], format))
- if next >= now:
- return next - now
- return -1
+ # Return (positive) seconds to the next Lunar eclipe or -1.
+ for date_string in full_moon_array:
+ if date_string[-1:] != "_":
+ next = time.mktime(time.strptime(date_string[:-1], format))
+ if next >= now:
+ return next - now
+ return -1
def last_lunar_eclipse_sec_at_time(now):
- # Return (positive) seconds to the last Lunar eclipe or -1.
- last = -1
- for date_string in full_moon_array:
- if date_string[-1:] != "_":
- then = time.mktime(time.strptime(date_string[:-1], format))
- if then >= now:
- break
- last = then
- if last == -1:
- return -1
- else:
- return now - last
+ # Return (positive) seconds to the last Lunar eclipe or -1.
+ last = -1
+ for date_string in full_moon_array:
+ if date_string[-1:] != "_":
+ then = time.mktime(time.strptime(date_string[:-1], format))
+ if then >= now:
+ break
+ last = then
+ if last == -1:
+ return -1
+ else:
+ return now - last
def next_solar_eclipse_sec_at_time(now):
- # Return (positive) seconds to the next Solar eclipe or -1.
- for date_string in new_moon_array:
- if date_string[-1:] != "_":
- next = time.mktime(time.strptime(date_string[:-1], format))
- if next >= now:
- return next - now
- return -1
+ # Return (positive) seconds to the next Solar eclipe or -1.
+ for date_string in new_moon_array:
+ if date_string[-1:] != "_":
+ next = time.mktime(time.strptime(date_string[:-1], format))
+ if next >= now:
+ return next - now
+ return -1
def correct_for_tz_and_dst(date_sec_of_event):
- # Time-zone and/or daylight-saving correction (internal data is UTC).
- if time.daylight == 0 or time.localtime(date_sec_of_event)[8] == 0:
- # Time-zone correction
- return time.timezone
- else:
- # Time-zone & daylight saving correction
- return time.altzone
+ # Time-zone and/or daylight-saving correction (internal data is UTC).
+ if time.daylight == 0 or time.localtime(date_sec_of_event)[8] == 0:
+ # Time-zone correction
+ return time.timezone
+ else:
+ # Time-zone & daylight saving correction
+ return time.altzone
def RecalcularFase(the_date):
- # Una fecha representada en segundos. Ejem:
- # format = "%Y-%m-%d %H:%M"
- # fecha = time.mktime(time.strptime("2012-06-21 15:00", format))
- last_new_moon_sec = last_new_moon_sec_at_time(the_date)
- next_new_moon_sec = next_new_moon_sec_at_time(the_date)
- last_full_moon_sec = last_full_moon_sec_at_time(the_date)
- next_full_moon_sec = next_full_moon_sec_at_time(the_date)
- last_quarter_moon_sec = last_quarter_moon_sec_at_time(the_date)
- next_quarter_moon_sec = next_quarter_moon_sec_at_time(the_date)
- phase_of_moon = None
- # Calculate phase percent of Moon based on nearest two data values
- if next_full_moon_sec <= next_new_moon_sec:
- if next_quarter_moon_sec <= next_full_moon_sec:
- phase_of_moon = (last_new_moon_sec / (last_new_moon_sec + next_quarter_moon_sec)) * 0.25
- else:
- phase_of_moon = (last_quarter_moon_sec / (last_quarter_moon_sec + next_full_moon_sec)) * 0.25 + 0.25
- else:
- if next_quarter_moon_sec <= next_new_moon_sec:
- phase_of_moon = (last_full_moon_sec / (last_full_moon_sec + next_quarter_moon_sec)) * 0.25 + 0.5
- else:
- phase_of_moon = (last_quarter_moon_sec / (last_quarter_moon_sec + next_new_moon_sec)) * 0.25 + 0.75
- return phase_of_moon
+ # Una fecha representada en segundos. Ejem:
+ # format = "%Y-%m-%d %H:%M"
+ # fecha = time.mktime(time.strptime("2012-06-21 15:00", format))
+ last_new_moon_sec = last_new_moon_sec_at_time(the_date)
+ next_new_moon_sec = next_new_moon_sec_at_time(the_date)
+ last_full_moon_sec = last_full_moon_sec_at_time(the_date)
+ next_full_moon_sec = next_full_moon_sec_at_time(the_date)
+ last_quarter_moon_sec = last_quarter_moon_sec_at_time(the_date)
+ next_quarter_moon_sec = next_quarter_moon_sec_at_time(the_date)
+ phase_of_moon = None
+
+ # Calculate phase percent of Moon based on nearest two data values
+ if next_full_moon_sec <= next_new_moon_sec:
+ if next_quarter_moon_sec <= next_full_moon_sec:
+ phase_of_moon = (last_new_moon_sec / (last_new_moon_sec + next_quarter_moon_sec)) * 0.25
+
+ else:
+ phase_of_moon = (last_quarter_moon_sec / (last_quarter_moon_sec + next_full_moon_sec)) * 0.25 + 0.25
+
+ else:
+ if next_quarter_moon_sec <= next_new_moon_sec:
+ phase_of_moon = (last_full_moon_sec / (last_full_moon_sec + next_quarter_moon_sec)) * 0.25 + 0.5
+
+ else:
+ phase_of_moon = (last_quarter_moon_sec / (last_quarter_moon_sec + next_new_moon_sec)) * 0.25 + 0.75
+
+ return phase_of_moon
def get_date_time():
- # Devolución tipo: Lunes 5 de Febrero de 2012
- dias= []
- for d in calendar.day_name:
- if d: dias.append(d)
- meses= []
- for m in calendar.month_name:
- if m: meses.append(m)
- t= time.localtime()
- anio= t.tm_year
- mes= meses[t.tm_mon -1]
- fecha= t.tm_mday
- dia= dias[t.tm_wday]#[t.tm_wday -1]
- hora= t.tm_hour
- minutos= t.tm_min
- segundos= t.tm_sec
- fecha= "%s %s de %s de %s" % (dia, fecha, mes, anio)
- hora= "%s:%s:%s" % (hora, minutos, segundos)
- return "%s %s" % (fecha, hora)
+ # Devolución tipo: Lunes 5 de Febrero de 2012
+ dias= []
+
+ for d in calendar.day_name:
+ if d: dias.append(d)
+
+ meses= []
+
+ for m in calendar.month_name:
+ if m: meses.append(m)
+
+ t= time.localtime()
+ anio= t.tm_year
+ mes= meses[t.tm_mon -1]
+ fecha= t.tm_mday
+ dia= dias[t.tm_wday]#[t.tm_wday -1]
+ hora= t.tm_hour
+ minutos= t.tm_min
+ segundos= t.tm_sec
+ fecha= "%s %s de %s de %s" % (dia, fecha, mes, anio)
+ hora= "%s:%s:%s" % (hora, minutos, segundos)
+ return "%s %s" % (fecha, hora)
def get_date_time_now():
- # Devolución tipo: año, mes, dia, hora (hora es string, los demás son enteros)
- t= time.localtime()
- anio= t.tm_year
- mes = t.tm_mon
- fecha= t.tm_mday
- hora= t.tm_hour
- minutos= t.tm_min
- hora= "%s:%s" % (hora, minutos)
- return (anio, mes, fecha, hora)
+
+ # Devolución tipo: año, mes, dia, hora (hora es string, los demás son enteros)
+ t= time.localtime()
+ anio= t.tm_year
+ mes = t.tm_mon
+ fecha= t.tm_mday
+ hora= t.tm_hour
+ minutos= t.tm_min
+ hora= "%s:%s" % (hora, minutos)
+ return (anio, mes, fecha, hora)
def get_semanas_del_mes(anio, mes):
- # Devuelve una lista de semanas.
- # Cada semana es una lista con las fechas del mes que le corresponde.
- # Cada semana comienza en lunes.
- # Las fechas 0 corresponden al mes pasado o al siguiente.
- calendario= calendar.Calendar()
- semanas= calendario.monthdayscalendar(anio, mes)
- return semanas
-
+
+ # Devuelve una lista de semanas.
+ # Cada semana es una lista con las fechas del mes que le corresponde.
+ # Cada semana comienza en lunes.
+ # Las fechas 0 corresponden al mes pasado o al siguiente.
+ calendario= calendar.Calendar()
+ semanas= calendario.monthdayscalendar(anio, mes)
+ return semanas