From 644351b5079b940248ea9e8a5be4e24dc9715341 Mon Sep 17 00:00:00 2001 From: shaoziyang Date: Sat, 23 Nov 2019 23:30:51 +0800 Subject: [PATCH] add range check for getYear(), getHour(), getMinute(), getSecond() --- ds1307.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ds1307.ts b/ds1307.ts index 6c40a86..8ed8c3a 100644 --- a/ds1307.ts +++ b/ds1307.ts @@ -81,7 +81,7 @@ namespace DS1307 { //% weight=99 blockGap=8 //% parts=DS1307 trackArgs=0 export function getYear(): number { - return (HexToDec(getReg(DS1307_REG_YEAR)) + 2000) + return Math.min(HexToDec(getReg(DS1307_REG_YEAR)), 99) + 2000 } /** @@ -168,7 +168,7 @@ namespace DS1307 { //% weight=95 blockGap=8 //% parts=DS1307 trackArgs=0 export function getHour(): number { - return HexToDec(getReg(DS1307_REG_HOUR)) % 24 + return Math.min(HexToDec(getReg(DS1307_REG_HOUR)), 23) } /** @@ -190,7 +190,7 @@ namespace DS1307 { //% weight=94 blockGap=8 //% parts=DS1307 trackArgs=0 export function getMinute(): number { - return HexToDec(getReg(DS1307_REG_MINUTE)) % 60 + return Math.min(HexToDec(getReg(DS1307_REG_MINUTE)), 59) } /** @@ -212,7 +212,7 @@ namespace DS1307 { //% weight=93 blockGap=8 //% parts=DS1307 trackArgs=0 export function getSecond(): number { - return HexToDec(getReg(DS1307_REG_SECOND)) % 60 + return Math.min(HexToDec(getReg(DS1307_REG_SECOND)), 59) } /**