Skip to content

Commit

Permalink
Anchors away!
Browse files Browse the repository at this point in the history
  • Loading branch information
bsiever committed Jun 19, 2020
1 parent 4204420 commit 6ad91f9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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:

Expand All @@ -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:

Expand All @@ -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)
Expand All @@ -271,39 +271,39 @@ 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()
```

Reports the time (in seconds) since the micro:bit started.

## Minute Changing #timeanddate-onMinuteChanged
## Minute Changing #timeanddate-onminutechanged

```sig
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)
```
The provided code will run when the hour changes.


## Day Changing #timeanddate-onDayChanged
## Day Changing #timeanddate-ondaychanged

```sig
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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion timeanddate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6ad91f9

Please sign in to comment.