natural-time-js 1.1.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [2.0.1] - 2024-03-26
9
+
10
+ ### Fixed
11
+ - Fixed Southern hemisphere mustache angle calculations
12
+ - Added .npmignore file for better package distribution
13
+
14
+ ## [2.0.0]
15
+
16
+ ### Added
17
+ - Switch to typescript
18
+ - Documentation with JSDoc
19
+ - Complete suite of test files with JEST
20
+ - Reorganize files structure (breaking changes)
21
+
22
+ ## [1.1.1]
23
+
24
+ ### Fixed
25
+ - Initial public release with basic functionality
26
+ - Core natural time calculations
27
+ - Basic formatting options
package/README.md CHANGED
@@ -1,161 +1,153 @@
1
- # Natural time - JavaScript
1
+ # Natural Time JS
2
2
 
3
- Natural time is a fresh, elegant, and coherent way of measuring the movements of time here on the Earth.
3
+ A revolutionary approach to time measurement, realigning human experience with nature's rhythms.
4
4
 
5
- This **new time standard** is based on common sense and the observation of natural cycles.
5
+ ## The Natural Time Paradigm
6
6
 
7
- ![Natural time app](.github/natural-time-app.jpg)
8
-
9
- Play with natural time at [https://naturaltime.app/](https://naturaltime.app/)
10
-
11
- ### JavaScript library
7
+ Our current time system - the Gregorian calendar with its arbitrary months and 24-hour days - is a human construct disconnected from natural cycles. Natural Time proposes a return to cosmic truth:
12
8
 
13
- This repository contains the JavaScript implementation of natural time.
14
9
 
15
- `index.js`: This class translates artificial dates to natural dates.
16
- `context.js`: Collection of utility functions for calculating sky context and events like moon phase, sunrise and sunset ...
10
+ - **Circular Time**: Days measured in 360 degrees, following the sun's continuous journey
11
+ - **Location-Aware**: Time calculations adjusted to your longitude, acknowledging Earth's rotation
12
+ - **Solar-Anchored Years**: Each year begins at winter solstice, nature's true new year marker
13
+ - **13 Perfect Moons**: 28-day cycles matching the moon's natural rhythm (364 days)
14
+ - **Rainbow Days**: 1-2 days outside the count to honor year completion and solar alignment
17
15
 
18
- ### Natural time specifications
19
16
 
20
- How are natural years, moons, days, and time defined ?
17
+ This isn't just a calendar reform - it's a return to measuring time through observable celestial events that have guided humanity for millennia.
21
18
 
22
- Read the full specifications of natural time here: [github.com/sylvain441/natural-time](https://github.com/sylvain441/natural-time)
19
+ ## Try Natural Time
23
20
 
24
- ### Web application
21
+ 🌟 **Experience it yourself!** The best way to understand Natural Time is to try it:
25
22
 
26
- You can play with natural time at [https://naturaltime.app/](https://naturaltime.app/). It both works online and offline thanks to this JavaScript library.
27
23
 
28
24
  ![Natural time app](.github/natural-time-app.jpg)
29
25
 
30
- # Javascript API
26
+ - **Web App**: Visit [naturaltime.app](https://naturaltime.app/) to see it in action
27
+ - **Source Code**: Explore the app's implementation at [github.com/sylvain441/natural-time-app](https://github.com/sylvain441/natural-time-app)
28
+ - **Features**:
29
+ - Works offline
30
+ - Location-aware time calculations
31
+ - Beautiful visualization of natural cycles
32
+ - Powered by this JavaScript library
31
33
 
32
- > If you know how to deal with typescript/typings/documentation this repo may appreciate your help. [Contribute here](#contribute)
33
-
34
- ## Instalation
35
-
36
- Install NPM package with your terminal:
34
+ ## Installation
37
35
 
38
36
  ```console
39
37
  npm install natural-time-js
40
38
  ```
41
39
 
42
- ## `NaturalDate` Class
40
+ ## Usage
41
+
42
+ ### NaturalDate Class
43
43
 
44
- The `NaturalDate` class translates artificial dates into natural dates.
44
+ The core class for working with Natural Time:
45
45
 
46
46
  ```javascript
47
47
  import { NaturalDate } from 'natural-time-js';
48
48
 
49
- let artificialDate = new Date();
50
- let longitude = 5.2;
51
-
52
- let naturalDate = new NaturalDate(artificialDate, longitude);
49
+ // Convert current time at longitude 5.2° E
50
+ const naturalDate = new NaturalDate(new Date(), 5.2);
51
+ console.log(naturalDate.toString()); // "004)04)01 113°00 NT+5.2"
53
52
  ```
54
53
 
55
- Once instanciated, the `naturalDate` object holds many computed variables available for your usage:
54
+ #### Properties
56
55
 
57
56
  ```javascript
58
- unixTime; // Artificial gregorian date (UNIX timestamp)
59
- longitude; // Longitude (between -180° to +180°)
60
-
61
- year; // Current year (year 1: 2012/2013)
62
- moon; // Current moon (between 1 and 14)
63
-
64
- week; // Current week (between 1 and 53)
65
- weekOfMoon; // Current week of the moon (between 1 and 4)
66
-
67
- day; // Number of days passed since END_OF_ARTIFICIAL_TIME
68
- dayOfYear; // Current day of the year (between 1 and 366)
69
- dayOfMoon; // Current day of the moon (between 1 and 28)
70
- dayOfWeek; // Current day of the week (between 1 and 7)
71
-
72
- isRainbowDay; // True if current day is rainbow day
73
-
74
- time; // Current time (between 0 and 359°999999...)
75
-
76
- yearStart; // Beginning of the year at the current longitude (UNIX timestamp)
77
- yearDuration; // Numbers of days in the current year (between 365 and 366)
78
- nadir; // Beginning of the day at the current longitude (UNIX timestamp)
79
-
80
- static END_OF_ARTIFICIAL_TIME = 1356091200000; // 2012-12-22 00:00:00 at +180° East;
81
- static MILLISECONDS_PER_DAY = 86400000; // 24*60*60*1000
57
+ // Time Properties
58
+ naturalDate.unixTime; // Artificial gregorian date (UNIX timestamp)
59
+ naturalDate.time; // Current time in degrees (0-359.999...)
60
+ naturalDate.nadir; // Beginning of the day at current longitude (UNIX timestamp)
61
+
62
+ // Location
63
+ naturalDate.longitude; // Longitude (-180° to +180°)
64
+
65
+ // Year Properties
66
+ naturalDate.year; // Current year (year 1: 2012/2013)
67
+ naturalDate.yearStart; // Beginning of the year at current longitude (UNIX timestamp)
68
+ naturalDate.yearDuration;// Days in current year (365 or 366)
69
+ naturalDate.dayOfYear; // Current day of the year (1-366)
70
+
71
+ // Moon Properties
72
+ naturalDate.moon; // Current moon (1-13, or 14 for rainbow days)
73
+ naturalDate.dayOfMoon; // Current day of the moon (1-28)
74
+ naturalDate.weekOfMoon; // Current week of the moon (1-4)
75
+
76
+ // Week Properties
77
+ naturalDate.week; // Current week (1-53)
78
+ naturalDate.dayOfWeek; // Current day of the week (1-7)
79
+
80
+ // Special Properties
81
+ naturalDate.isRainbowDay;// True if current day is rainbow day
82
+ naturalDate.day; // Days since END_OF_ARTIFICIAL_TIME
83
+
84
+ // Constants
85
+ NaturalDate.END_OF_ARTIFICIAL_TIME; // 1356091200000 (2012-12-21 12:00:00 UTC)
86
+ NaturalDate.MILLISECONDS_PER_DAY; // 86400000 (24*60*60*1000)
82
87
  ```
83
88
 
84
- **Utility functions**
89
+ #### Utility Methods
85
90
 
86
- ```javascript
87
- naturalDate.toString() // "004)04)01 113°00 NT+5.2"
88
- naturalDate.toDateString(separator = ')') // "004)04)01"
89
- naturalDate.toTimeString(decimals = 2, rounding = 1) // "113°00"
90
- naturalDate.toLongitudeString(decimals = 1) // "NT+5.2"
91
- naturalDate.toYearString() // "004"
92
- naturalDate.toMoonString() // "04"
93
- naturalDate.toDayOfMoonString() // "01"
91
+ ```javascript
92
+ naturalDate.toString(); // "004)04)01 113°00 NT+5.2"
93
+ naturalDate.toDateString(); // "004)04)01"
94
+ naturalDate.toTimeString(); // "113°00"
95
+ naturalDate.toLongitudeString(); // "NT+5.2"
96
+ naturalDate.toYearString(); // "004"
97
+ naturalDate.toMoonString(); // "04"
98
+ naturalDate.toDayOfMoonString(); // "01"
94
99
  ```
95
100
 
96
- More functions should be available later to make the NaturalDate class API mimic the native javascript Date class (ex: naturalDate.setYear(year)). Your help is welcome for this to happen ;-)
97
-
98
- ## `NaturalDateContext` functions
99
-
100
- The NaturalDateContext.js file contains utility functions to bring some astronomical context to the natural date (ex: altitude of the sun, phase of the moon).
101
-
102
- ```javascript
103
- import { NaturalSunAltitude, NaturalSunEvents, NaturalMoonPosition, NaturalMoonEvents } from 'natural-time-js/context';
101
+ ### Astronomical Functions
104
102
 
105
- // Gizeh pyramide
106
- let latitude: 29.9791;
107
- let longitude: 31.1341;
103
+ Calculate precise celestial events and positions:
108
104
 
109
- let naturalDate = new NaturalDate(new Date(), longitude);
110
-
111
- NaturalSunAltitude(naturalDate, latitude);
112
- // altitude: 31.779736404754367,
113
- // highestAltitude: 62.32114911751647
105
+ ```javascript
106
+ import { NaturalSunEvents, NaturalMoonPosition } from 'natural-time-js';
107
+
108
+ // Giza Pyramid coordinates
109
+ const latitude = 29.9791;
110
+ const longitude = 31.1341;
111
+ const naturalDate = new NaturalDate(new Date(), longitude);
112
+
113
+ // Get sun events for the day
114
+ const sunEvents = NaturalSunEvents(naturalDate, latitude);
115
+ console.log(sunEvents.sunrise); // 70.567° (time in natural degrees)
116
+ console.log(sunEvents.sunset); // 287.910°
117
+
118
+ // Get current moon position and phase
119
+ const moonInfo = NaturalMoonPosition(naturalDate, latitude);
120
+ console.log(moonInfo.phase); // 74.861° (percentage of lunar cycle)
121
+ console.log(moonInfo.altitude); // 64.323° (degrees above horizon)
122
+ ```
114
123
 
115
- NaturalSunEvents(naturalDate, latitude);
116
- // sunrise: 70.56708493448893,
117
- // sunset: 287.9105974344889,
118
- // nightStart: 306.43507660115563,
119
- // nightEnd: 52.13781826782227,
120
- // morningGoldenHour: 80.8551891011556,
121
- // eveningGoldenHour: 277.58920993448896
124
+ ## Documentation
122
125
 
123
- NaturalMoonPosition(naturalDate, latitude);
124
- // phase: 74.86175469141531,
125
- // altitude: 64.32391838504756,
126
- // highestAltitude: 69.53997976716451
126
+ The library is fully documented using JSDoc. Generate the documentation with:
127
127
 
128
- NaturalMoonEvents(naturalDate, latitude);
129
- // moonrise: 139.14544743448894,
130
- // moonset: 10.624722434488932
128
+ ```bash
129
+ npm run docs
131
130
  ```
132
131
 
133
- **Important !**
134
- Utility functions return time-distance from 0° or false if the event does not occur during this day (ex: no sunrise at the north pole during winter).
132
+ For live documentation updates during development:
135
133
 
136
- ## Roadmap
134
+ ```bash
135
+ npm run docs:dev
136
+ ```
137
137
 
138
- 1. Test in real life
139
- 2. Add typescript compatibility
140
- 3. Make NaturalDate feel like the Javascript native Date Class by adding features like
141
- - getTime()
142
- - setMoon()
143
- - ...
144
- 4. Make NaturalTime available for other programming languages
138
+ This creates HTML documentation in the `docs` directory.
145
139
 
146
- # Contribute
140
+ ## Contribute
147
141
 
148
142
  Natural time is open to contributions from free-thinking minds. Find your way through Github or email at: [sylvain441@proton.me](mailto:sylvain441@proton.me) to get in touch.
149
143
 
150
- # License
144
+ ## License
151
145
 
152
146
  Read [full license](./LICENSE) (Creative Common Zero)
153
147
 
154
148
  Natural time is completely free to use, play, transform, improve... It operates under the law of Love. Follow your heart, fork it, spoon it! There is no need to ask for permission to do anything with it.
155
149
 
156
- Natural time is supposed to bring joy and ease to human life, not the opposite. What you make out of it is up to you and the assistance of life forces.
157
-
158
- # Acknowledgments
150
+ ## Acknowledgments
159
151
 
160
152
  Natural time has been baking for a long time in a goat's mind while traveling around the world. Infinite gratitude to my beloved friends Uncle Skywalker and Ik: your precious insights into the Mayan universe were so inspiring.
161
153
 
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ presets: [
3
+ ['@babel/preset-env', {
4
+ targets: {
5
+ node: 'current'
6
+ }
7
+ }]
8
+ ]
9
+ };
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @module natural-time-js/celestial
3
+ * @description The cosmic heartbeat of natural time - precise astronomical calculations that connect us to the rhythms of sun and moon.
4
+ *
5
+ * While artificial time ignores the sky, natural time is anchored to celestial reality.
6
+ * This module provides the astronomical foundation that makes natural time truly natural:
7
+ * - Exact solar positions throughout the day
8
+ * - Precise lunar phases and cycles
9
+ * - Solstice and equinox calculations
10
+ * - Location-aware sunrise, sunset, moonrise and moonset times
11
+ */
12
+ import { NaturalDate } from '../core/NaturalDate';
13
+ /**
14
+ * Hemisphere identifiers for geographical calculations.
15
+ */
16
+ export declare enum HEMISPHERES {
17
+ /** Northern hemisphere (latitude >= 0) */
18
+ NORTH = "NORTH",
19
+ /** Southern hemisphere (latitude < 0) */
20
+ SOUTH = "SOUTH"
21
+ }
22
+ /**
23
+ * Day numbers marking the start and end of summer season.
24
+ */
25
+ export declare const SEASONS: {
26
+ /** Day 91 (typically April 1st) - Start of summer in Northern hemisphere */
27
+ readonly SUMMER_START_DAY: 91;
28
+ /** Day 273 (typically September 30th) - End of summer in Northern hemisphere */
29
+ readonly SUMMER_END_DAY: 273;
30
+ };
31
+ /**
32
+ * Solar altitude thresholds in degrees for different daylight conditions.
33
+ */
34
+ export declare const ANGLES: {
35
+ /** Altitude below which astronomical night begins (-12°) */
36
+ readonly NIGHT_ALTITUDE: -12;
37
+ /** Altitude below which golden hour lighting occurs (6°) */
38
+ readonly GOLDEN_HOUR_ALTITUDE: 6;
39
+ };
40
+ /**
41
+ * Interface for sun altitude information
42
+ */
43
+ interface SunAltitude {
44
+ altitude: number;
45
+ highestAltitude: number;
46
+ }
47
+ /**
48
+ * Interface for sun events
49
+ */
50
+ interface SunEvents {
51
+ sunrise: number;
52
+ sunset: number;
53
+ nightStart: number;
54
+ nightEnd: number;
55
+ morningGoldenHour: number;
56
+ eveningGoldenHour: number;
57
+ }
58
+ /**
59
+ * Interface for moon position information
60
+ */
61
+ interface MoonPosition {
62
+ altitude: number;
63
+ phase: number;
64
+ illumination: number;
65
+ }
66
+ /**
67
+ * Interface for moon events
68
+ */
69
+ interface MoonEvents {
70
+ moonrise: number;
71
+ moonset: number;
72
+ highestAltitude: number;
73
+ }
74
+ /**
75
+ * Interface for mustaches range information
76
+ */
77
+ interface MustachesRange {
78
+ winterSunrise: number;
79
+ winterSunset: number;
80
+ summerSunrise: number;
81
+ summerSunset: number;
82
+ averageMustacheAngle: number;
83
+ }
84
+ /**
85
+ * Calculates the sun's altitude at a specific natural time and location.
86
+ */
87
+ export declare function NaturalSunAltitude(naturalDate: NaturalDate, latitude: number): SunAltitude;
88
+ /**
89
+ * Calculates sun events for a specific natural date and location.
90
+ */
91
+ export declare function NaturalSunEvents(naturalDate: NaturalDate, latitude: number): SunEvents;
92
+ /**
93
+ * Calculates the moon's position and phase.
94
+ */
95
+ export declare function NaturalMoonPosition(naturalDate: NaturalDate, latitude: number): MoonPosition;
96
+ /**
97
+ * Calculates moon events for a specific natural date and location.
98
+ */
99
+ export declare function NaturalMoonEvents(naturalDate: NaturalDate, latitude: number): MoonEvents;
100
+ /**
101
+ * Calculates the range of sun positions between winter and summer solstices (average mustaches angle)
102
+ */
103
+ export declare function MustachesRange(naturalDate: NaturalDate, latitude: number): MustachesRange;
104
+ export {};