comparison MakeWaypoints.kt @ 9:a56d3d3b5efd

Reject out of range latitide and longitide values.
author David Barts <n5jrn@me.com>
date Wed, 25 Aug 2021 08:45:36 -0700
parents 290b0b2a584b
children
comparison
equal deleted inserted replaced
8:290b0b2a584b 9:a56d3d3b5efd
6 import javax.xml.stream.* 6 import javax.xml.stream.*
7 import java.io.FileOutputStream 7 import java.io.FileOutputStream
8 import java.text.SimpleDateFormat 8 import java.text.SimpleDateFormat
9 import java.util.Date 9 import java.util.Date
10 import java.util.TimeZone 10 import java.util.TimeZone
11 import kotlin.math.abs
11 12
12 private const val MYNAME = "MakeWaypoints" 13 private const val MYNAME = "MakeWaypoints"
13 private const val CHARSET = "UTF-8" 14 private const val CHARSET = "UTF-8"
14 private val WP_TIME_FORMAT = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").apply { 15 private val WP_TIME_FORMAT = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").apply {
15 timeZone = TimeZone.getTimeZone("GMT") 16 timeZone = TimeZone.getTimeZone("GMT")
70 } 71 }
71 val (lat, long) = if (latFirst) 72 val (lat, long) = if (latFirst)
72 Pair(parts[0].trim(), parts[1].trim()) 73 Pair(parts[0].trim(), parts[1].trim())
73 else 74 else
74 Pair(parts[1].trim(), parts[0].trim()) 75 Pair(parts[1].trim(), parts[0].trim())
75 if (lat.toDoubleOrNull() == null || long.toDoubleOrNull() == null) { 76 val dLat = lat.toDoubleOrNull()
77 val dLong = long.toDoubleOrNull()
78 if (dLat == null || abs(dLat) > 90.0 || dLong == null || abs(dLong) > 180.0) {
76 System.err.println(invalid) 79 System.err.println(invalid)
77 continue 80 continue
78 } 81 }
79 print("Name: ") 82 print("Name: ")
80 val name = readLine() 83 val name = readLine()