summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2017-09-05 01:15:25 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2017-09-08 21:08:53 +0200
commit172efd71798a00469658b0f0e6fc730bac6fa5fe (patch)
tree9317f6b3f570eb9bd1a95ef607fed871bc5f44c8
parent90fe21af88b7191a7f3a979040ec07c3ed03960b (diff)
downloadcalcurse-172efd71798a00469658b0f0e6fc730bac6fa5fe.tar.gz
calcurse-172efd71798a00469658b0f0e6fc730bac6fa5fe.zip
Remove phase of moon feature
The computation never really worked before and it seems like the feature is not very helpful, sometimes even confusing (see GitHub issue #21). The macro ISLEAP is moved to calcurse.h. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r--src/calcurse.h3
-rw-r--r--src/ui-calendar.c181
-rw-r--r--src/ui-day.c1
-rw-r--r--src/utils.c2
4 files changed, 2 insertions, 185 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index 10e60aa..133b6b9 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -302,6 +302,8 @@ struct date {
unsigned yyyy;
};
+#define ISLEAP(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
+
/* Appointment definition. */
struct apoint {
long start; /* seconds since 1 jan 1970 */
@@ -740,7 +742,6 @@ void ui_calendar_change_day(int);
void ui_calendar_move(enum move, int);
long ui_calendar_start_of_year(void);
long ui_calendar_end_of_year(void);
-const char *ui_calendar_get_pom(time_t);
/* config.c */
void config_load(void);
diff --git a/src/ui-calendar.c b/src/ui-calendar.c
index 9ea31e1..a2a0e8b 100644
--- a/src/ui-calendar.c
+++ b/src/ui-calendar.c
@@ -44,29 +44,6 @@
#include "calcurse.h"
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-#define EPOCH 90
-#define EPSILONg 279.403303 /* solar ecliptic long at EPOCH */
-#define RHOg 282.768422 /* solar ecliptic long of perigee at EPOCH */
-#define ECCEN 0.016713 /* solar orbit eccentricity */
-#define lzero 318.351648 /* lunar mean long at EPOCH */
-#define Pzero 36.340410 /* lunar mean long of perigee at EPOCH */
-#define Nzero 318.510107 /* lunar mean long of node at EPOCH */
-
-#define ISLEAP(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
-
-enum pom {
- NO_POM,
- FIRST_QUARTER,
- FULL_MOON,
- LAST_QUARTER,
- NEW_MOON,
- MOON_PHASES
-};
-
static struct date today, slctd_day;
static unsigned ui_calendar_view, week_begins_on_monday;
static pthread_mutex_t date_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -780,161 +757,3 @@ long ui_calendar_end_of_year(void)
return (long)(timer - 1);
}
-
-/*
- * The pom, potm, dotr, adj360 are used to compute the current
- * phase of the moon.
- * The code is based on the OpenBSD version of pom(6).
- * Below is reported the copyright notice.
- */
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software posted to USENET.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * dtor --
- * convert degrees to radians
- */
-static double dtor(double deg)
-{
- return deg * M_PI / 180;
-}
-
-/*
- * adj360 --
- * adjust value so 0 <= deg <= 360
- */
-static void adj360(double *deg)
-{
- for (;;)
- if (*deg < 0.0)
- *deg += 360.0;
- else if (*deg > 360.0)
- *deg -= 360.0;
- else
- break;
-}
-
-/*
- * Phase of the Moon. Calculates the current phase of the moon.
- * Based on routines from `Practical Astronomy with Your Calculator',
- * by Duffett-Smith. Comments give the section from the book that
- * particular piece of code was adapted from.
- *
- * -- Keith E. Brandt VIII 1984
- *
- * Updated to the Third Edition of Duffett-Smith's book, IX 1998
- *
- */
-
-/*
- * potm --
- * given number of days since January 1st 1990, 00:00
- * (incl. hours and minutes as a fraction of a day),
- * return phase of the moon as a percentage.
- */
-static double potm(double days)
-{
- double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
- double A4, lprime, V, ldprime, D, Nm;
-
- N = 360.0 * days / 365.242191; /* sec 46 #3 */
- adj360(&N);
- Msol = N + EPSILONg - RHOg; /* sec 46 #4 */
- adj360(&Msol);
- Ec = 360 / M_PI * ECCEN * sin(dtor(Msol)); /* sec 46 #5 */
- LambdaSol = N + Ec + EPSILONg; /* sec 46 #6 */
- adj360(&LambdaSol);
- l = 13.1763966 * days + lzero; /* sec 65 #4 */
- adj360(&l);
- Mm = l - (0.1114041 * days) - Pzero; /* sec 65 #5 */
- adj360(&Mm);
- Nm = Nzero - (0.0529539 * days); /* sec 65 #6 */
- adj360(&Nm);
- Ev = 1.2739 * sin(dtor(2 * (l - LambdaSol) - Mm)); /* sec 65 #7 */
- Ac = 0.1858 * sin(dtor(Msol)); /* sec 65 #8 */
- A3 = 0.37 * sin(dtor(Msol));
- Mmprime = Mm + Ev - Ac - A3; /* sec 65 #9 */
- Ec = 6.2886 * sin(dtor(Mmprime)); /* sec 65 #10 */
- A4 = 0.214 * sin(dtor(2 * Mmprime)); /* sec 65 #11 */
- lprime = l + Ev + Ec - Ac + A4; /* sec 65 #12 */
- V = 0.6583 * sin(dtor(2 * (lprime - LambdaSol))); /* sec 65 #13 */
- ldprime = lprime + V; /* sec 65 #14 */
- D = ldprime - LambdaSol; /* sec 67 #2 */
- return 50.0 * (1 - cos(dtor(D))); /* sec 67 #3 */
-}
-
-static double pom(time_t tmpt)
-{
- struct tm *GMT;
- double days;
- int cnt;
-
- GMT = gmtime(&tmpt);
- days = (GMT->tm_yday + 1) + ((GMT->tm_hour + (GMT->tm_min / 60.0) +
- (GMT->tm_sec / 3600.0)) / 24.0);
- for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt)
- days += ISLEAP(cnt + TM_YEAR_BASE) ? 366 : 365;
- /* Selected time could be before EPOCH */
- for (cnt = GMT->tm_year; cnt < EPOCH; ++cnt)
- days -= ISLEAP(cnt + TM_YEAR_BASE) ? 366 : 365;
-
- return potm(days);
-}
-
-/*
- * Return a pictogram representing the current phase of the moon.
- * Careful: date is the selected day in calendar at 00:00,
- * and so represents the phase of the moon at midnight.
- */
-const char *ui_calendar_get_pom(time_t date)
-{
- const char *pom_pict[MOON_PHASES] =
- { " ", "|) ", "(|)", "(| ", " | " };
- enum pom phase = NO_POM;
- const double half = 50.0;
-
- date += DAYINSEC / 2; /* adjust to noon */
- double pom_n_b = pom(date - DAYINSEC); /* noon before */
- double pom_m_b = pom(date - DAYINSEC / 2); /* midnight before */
- double pom_n = pom(date); /* noon */
- double pom_m_a = pom(date + DAYINSEC / 2); /* midnight after */
- double pom_n_a = pom(date + DAYINSEC); /* noon after */
-
- if (pom_n > pom_n_b && pom_n > pom_n_a)
- phase = FULL_MOON;
- else if (pom_n < pom_n_b && pom_n < pom_n_a)
- phase = NEW_MOON;
- else if (pom_m_b < half && half < pom_m_a)
- phase = FIRST_QUARTER;
- else if (pom_m_b > half && half > pom_m_a)
- phase = LAST_QUARTER;
- return pom_pict[phase];
-}
diff --git a/src/ui-day.c b/src/ui-day.c
index 1cc9eb0..6a06941 100644
--- a/src/ui-day.c
+++ b/src/ui-day.c
@@ -916,7 +916,6 @@ static char *fmt_day_heading(time_t date)
localtime_r(&date, &tm);
string_init(&s);
- string_printf(&s, "%s ", ui_calendar_get_pom(date));
string_catftime(&s, conf.day_heading, &tm);
return string_buf(&s);
}
diff --git a/src/utils.c b/src/utils.c
index e0e35bc..11d4582 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -51,8 +51,6 @@
#include "calcurse.h"
#include "sha1.h"
-#define ISLEAP(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
-
#define FS_EXT_MAXLEN 64
enum format_specifier {