Skip to content

Commit e3e425e

Browse files
committed
fixed year(), getHour(), getMinute(), getSecond() bug
fixed year(), getHour(), getMinute(), getSecond() bug in simulator. Thanks @edbye found the bug
1 parent 527c0df commit e3e425e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ds1302.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ namespace DS1302 {
104104
//% weight=80 blockGap=8
105105
//% parts="DS1302"
106106
getYear(): number {
107-
return (HexToDec(this.getReg(DS1302_REG_YEAR + 1)) + 2000)
107+
return Math.min(HexToDec(this.getReg(DS1302_REG_YEAR + 1)), 99) + 2000
108108
}
109109

110110
/**
@@ -191,7 +191,7 @@ namespace DS1302 {
191191
//% weight=72 blockGap=8
192192
//% parts="DS1302"
193193
getHour(): number {
194-
return HexToDec(this.getReg(DS1302_REG_HOUR + 1)) % 24
194+
return Math.min(HexToDec(this.getReg(DS1302_REG_HOUR + 1)), 23)
195195
}
196196

197197
/**
@@ -213,7 +213,7 @@ namespace DS1302 {
213213
//% weight=72 blockGap=8
214214
//% parts="DS1302"
215215
getMinute(): number {
216-
return HexToDec(this.getReg(DS1302_REG_MINUTE + 1)) % 60
216+
return Math.min(HexToDec(this.getReg(DS1302_REG_MINUTE + 1)), 59)
217217
}
218218

219219
/**
@@ -235,7 +235,7 @@ namespace DS1302 {
235235
//% weight=70 blockGap=8
236236
//% parts="DS1302"
237237
getSecond(): number {
238-
return HexToDec(this.getReg(DS1302_REG_SECOND + 1)) % 60
238+
return Math.min(HexToDec(this.getReg(DS1302_REG_SECOND + 1)), 59)
239239
}
240240

241241
/**

0 commit comments

Comments
 (0)