@@ -93,7 +93,8 @@ Move to `micropython-samples` on the PC, run `rshell` and issue:
93
93
```
94
94
` mip ` installs the following files in the ` sched ` directory.
95
95
* ` sun_moon.py `
96
- * ` sun_moon_test.py ` A test/demo script.
96
+ * ` sun_moon_test.py ` A test/demo script for the above.
97
+ * ` moonphase.py ` Determine lunar quarters and phase.
97
98
After installation the ` RiSet ` class may be accessed with
98
99
``` python
99
100
from sched.sun_moon import RiSet
@@ -402,6 +403,11 @@ time. Phases are calculated with respect to this datum. It may be changed using
402
403
` .set_day ` to enable future and past phases to be determined or to enable long
403
404
running applications to track time.
404
405
406
+ The module is imported as follows:
407
+ ``` python
408
+ from sched.moonphase import MoonPhase
409
+ ```
410
+
405
411
## 6.1 Constructor
406
412
407
413
* ` lto:float=0, dst = lambda x: x ` Local time offset in hours to UTC (-ve is
@@ -420,7 +426,7 @@ being full. The `text` arg determines how the value is returned: as text or as
420
426
function is provided to the constructor.
421
427
* ` phase() -> float) ` Returns moon phase where 0.0 <= phase < 1.0 with 0.5 being
422
428
full moon. The phase is that pertaining to the datum.
423
- * ` nextphase(, text: bool = True) ` This is a generator function. Each iteration
429
+ * ` nextphase(text: bool = True) ` This is a generator function. Each iteration
424
430
of the generator returns three values: the phase number, the lunation number and
425
431
the datetime of the phase. The ` text ` arg is as per ` .quarter() ` , defining the
426
432
format of the datetime.
@@ -435,7 +441,7 @@ per the constructor arg.
435
441
## 6.3 Usage examples
436
442
437
443
``` python
438
- from moonphase import MoonPhase
444
+ from sched. moonphase import MoonPhase
439
445
mp = MoonPhase() # datum is midnight last night
440
446
print (f " Full moon, current lunation { mp.quarter(2 )} " )
441
447
mp.set_day(0.5 ) # Adjust datum to noon today machine time
@@ -457,10 +463,11 @@ which is based on the machine clock. If the machine clock runs at a fixed offset
457
463
to UTC (which is recommended), a DST function can be used to enable reported
458
464
results to reflect local time.
459
465
460
- A DST function takes as input a time measured in seconds since the machine epoch
461
- (as returned by ` time.time() ` ) and returns that number adjusted for local time.
462
- The following example is for UK time, which adds one hour at 2:00 on the last
463
- Sunday in March, reverting to winter time at 2:00 on the last Sunday in October.
466
+ A DST function takes as input a datetime measured in seconds since the machine
467
+ epoch (as returned by ` time.time() ` ) and returns that number adjusted for local
468
+ time. The following example is for UK time, which adds one hour at 2:00 on the
469
+ last Sunday in March, reverting to winter time at 2:00 on the last Sunday in
470
+ October.
464
471
465
472
``` python
466
473
def uk_dst (secs_epoch : int ): # Change in March (3) and Oct (10)
@@ -476,8 +483,8 @@ def uk_dst(secs_epoch: int): # Change in March (3) and Oct (10)
476
483
return summer # +1 hr
477
484
# We are in March or October. Find the day in month of last Sunday.
478
485
ld = (wday + 31 - mday) % 7 # weekday of 31st.
479
- lsun = 31 - (1 + ld) % 7
480
- thresh = time.mktime((t[0 ], month, lsun, 2 , 0 , 0 , 6 , 0 ))
486
+ lsun = 31 - (1 + ld) % 7 # Monthday of last Sunday
487
+ thresh = time.mktime((t[0 ], month, lsun, 2 , 0 , 0 , 6 , 0 )) # 2am last Sunday in month
481
488
return summer if ((secs_epoch >= thresh) ^ (month == 10 )) else winter
482
489
```
483
490
0 commit comments