Skip to content

Commit 527c0df

Browse files
committed
change
Change value check method. Thanks @whaleygeek and @edbye found the bug.
1 parent 8cbf501 commit 527c0df

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

ds1302.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ namespace DS1302 {
125125
//% weight=78 blockGap=8
126126
//% parts="DS1302"
127127
getMonth(): number {
128-
let d = HexToDec(this.getReg(DS1302_REG_MONTH + 1))
129-
if ((d < 1) || (d > 12)) return 1
130-
return d
128+
return Math.max(Math.min(HexToDec(this.getReg(DS1302_REG_MONTH + 1)), 12), 1)
131129
}
132130

133131
/**
@@ -149,9 +147,7 @@ namespace DS1302 {
149147
//% weight=76 blockGap=8
150148
//% parts="DS1302"
151149
getDay(): number {
152-
let d = HexToDec(this.getReg(DS1302_REG_DAY + 1))
153-
if ((d < 1) || (d > 31)) return 1
154-
return d
150+
return Math.max(Math.min(HexToDec(this.getReg(DS1302_REG_DAY + 1)), 31), 1)
155151
}
156152

157153
/**
@@ -173,9 +169,7 @@ namespace DS1302 {
173169
//% weight=74 blockGap=8
174170
//% parts="DS1302"
175171
getWeekday(): number {
176-
let d = HexToDec(this.getReg(DS1302_REG_WEEKDAY + 1))
177-
if ((d < 1) || (d > 7)) return 1
178-
return d
172+
return Math.max(Math.min(HexToDec(this.getReg(DS1302_REG_WEEKDAY + 1)), 7), 1)
179173
}
180174

181175
/**

0 commit comments

Comments
 (0)