File tree Expand file tree Collapse file tree 1 file changed +3
-9
lines changed Expand file tree Collapse file tree 1 file changed +3
-9
lines changed Original file line number Diff line number Diff 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 /**
You can’t perform that action at this time.
0 commit comments