From 6ad91f9a51409a28c48475c2d5f2813a015cd5a1 Mon Sep 17 00:00:00 2001 From: Bill Siever Date: Fri, 19 Jun 2020 15:26:29 -0500 Subject: [PATCH] Anchors away! --- README.md | 24 ++++++++++++------------ test.ts | 14 +++++++------- timeanddate.ts | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 5c56fb3..53251ef 100644 --- a/README.md +++ b/README.md @@ -170,15 +170,15 @@ while (!(input.buttonIsPressed(Button.AB))) { # Full API -## Setting Time Using 24-hour Format #timeanddate-set24HourTime +## Setting Time Using 24-hour Format #timeanddate-set24hourtime Use `[timeanddate.set24HourTime()]` to set the time using 24-hour format (hours from 0-23, minutes from 0-59, seconds from 0-59). See [Setting the Time](#setting-the-time). -## Setting Time Using AM/PM Format #timeanddate-setTime +## Setting Time Using AM/PM Format #timeanddate-settime Use `[timeanddate.setTime()]` to set the time using am/pm format (hours from 1-12, minutes from 0-59, seconds from 0-59). See [Setting the Time](#setting-the-time). -## Setting the Date #timeanddate-setDate +## Setting the Date #timeanddate-setdate Use `[timeanddate.setDate()]` to set the date (month from 1-12, day from 1-31, year from 0000-9999). See [Setting the Time](#setting-the-time). @@ -213,7 +213,7 @@ Use the timestamp or the ``[timeanddate.numericTime()]`` block to get numeric v ### ~ -## Timestamps (string) #timeanddate-dateStamp +## Timestamps (string) #timeanddate-datestamp Often a "timestamp" is needed to record events, like when measurements are taken for a science experiment. Use: @@ -231,7 +231,7 @@ Use timestamps when logging events that happen over multiple days (more than 24 ### ~ -## Accessing numeric values of time / date #timeanddate-numericTime +## Accessing numeric values of time / date #timeanddate-numerictime Numeric values of time/date can be useful for things like alarm clocks. Use: @@ -257,7 +257,7 @@ when it had changed to 2020-01-02. The combined date and time would appear to b ### ~ -## Advancing and Adjusting Time #timeanddate-advanceBy +## Advancing and Adjusting Time #timeanddate-advanceby ```sig timeanddate.advanceBy(amount: number, unit: TimeUnit) @@ -271,7 +271,7 @@ It behaves like a mechanical clock: Advancing the minutes causes the hour to adv for adjusting the clocks accuracy (adding seconds occasionally if it's slow) or adjusting for changes in timezone or daylight savings time. -## Seconds the Micro:bit has been running #timeanddate-secondsSinceReset +## Seconds the Micro:bit has been running #timeanddate-secondssincereset ```sig timeanddate.secondsSinceReset() @@ -279,7 +279,7 @@ timeanddate.secondsSinceReset() Reports the time (in seconds) since the micro:bit started. -## Minute Changing #timeanddate-onMinuteChanged +## Minute Changing #timeanddate-onminutechanged ```sig timeAndDate.onMinuteChanged(handler: () => void) @@ -287,7 +287,7 @@ timeAndDate.onMinuteChanged(handler: () => void) The provided code will run when the minute changes. -## Hour Changing #timeanddate-onHourChanged +## Hour Changing #timeanddate-onhourchanged ```sig timeAndDate.onHourChanged(handler: () => void) @@ -295,7 +295,7 @@ timeAndDate.onHourChanged(handler: () => void) The provided code will run when the hour changes. -## Day Changing #timeanddate-onDayChanged +## Day Changing #timeanddate-ondaychanged ```sig timeAndDate.onDayChanged(handler: () => void) @@ -303,7 +303,7 @@ timeAndDate.onDayChanged(handler: () => void) The provided code will run when the day changes. -## Weekdays #timeanddate-dayOfWeek +## Weekdays #timeanddate-datetodayofweek Once you have the day, month, and year, you can use them on the: ```sig @@ -312,7 +312,7 @@ timeanddate.dateOfWeek() to determine the day of the week. It returns a numeric code, where 0 is Monday, 1 is Tuesday, etc. -## Day of the Year #timeanddate-dateToDayOfYear +## Day of the Year #timeanddate-datetodayofyear Once you have the day, month, and year, you can use them on the: ```sig diff --git a/test.ts b/test.ts index 99dc4f4..b15f2ee 100644 --- a/test.ts +++ b/test.ts @@ -154,13 +154,13 @@ assert("time4e", "1:59.59am", timeanddate.time(timeanddate.TimeFormat.HMMSSAMPM) // Test Day Of Week -assert("dow1", 0, timeanddate.dayOfWeek(1, 20, 2020)) -assert("dow2", 1, timeanddate.dayOfWeek(1, 21, 2020)) -assert("dow3", 5, timeanddate.dayOfWeek(2, 29, 2020)) -assert("dow4", 6, timeanddate.dayOfWeek(3, 1, 2020)) -assert("dow5", 0, timeanddate.dayOfWeek(3, 1, 2021)) -assert("dow6", 1, timeanddate.dayOfWeek(3, 1, 2022)) -assert("dow7", 4, timeanddate.dayOfWeek(3, 1, 2024)) +assert("dow1", 0, timeanddate.dateToDayOfWeek(1, 20, 2020)) +assert("dow2", 1, timeanddate.dateToDayOfWeek(1, 21, 2020)) +assert("dow3", 5, timeanddate.dateToDayOfWeek(2, 29, 2020)) +assert("dow4", 6, timeanddate.dateToDayOfWeek(3, 1, 2020)) +assert("dow5", 0, timeanddate.dateToDayOfWeek(3, 1, 2021)) +assert("dow6", 1, timeanddate.dateToDayOfWeek(3, 1, 2022)) +assert("dow7", 4, timeanddate.dateToDayOfWeek(3, 1, 2024)) // Test Day Of Year assert("doy1", 1, timeanddate.dateToDayOfYear(1, 1, 2020)) diff --git a/timeanddate.ts b/timeanddate.ts index 6346e4f..9d2f89c 100644 --- a/timeanddate.ts +++ b/timeanddate.ts @@ -343,7 +343,7 @@ namespace timeanddate { //% day.min=1 day.max=31 day.defl=20 //% year.min=2020 year.max=2050 year.defl=2020 //% weight=40 - export function dayOfWeek(month: Month, day: Day, year: Year): Weekday { + export function dateToDayOfWeek(month: Month, day: Day, year: Year): Weekday { let doy = dateToDayOfYear(month, day, year) // Gauss's Algorithm for Jan 1: https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week // R(1+5R(A-1,4)+4R(A-1,100)+6R(A-1,400),7)