import java.time.LocalTime ;
import java.time.format.DateTimeFormatter ;
import java.time.format.ResolverStyle ;
class TesteDatas {
private static final DateTimeFormatter FORMATO_HORAS = DateTimeFormatter
.ofPattern ( "HH:mm" )
.withResolverStyle ( ResolverStyle.STRICT ) ;
private static LocalTime faltando( LocalTime agora, LocalTime desejada) {
return desejada.minusHours ( agora.getHour ( ) ) .minusMinutes ( agora.getMinute ( ) ) ;
}
private static void mostrar
( LocalTime horario,
String objetivo
) { LocalTime desejada = LocalTime.parse ( objetivo, FORMATO_HORAS) ;
LocalTime falta = faltando( horario, desejada) ;
"Entre " + horario.format ( FORMATO_HORAS)
+ " e " + desejada.format ( FORMATO_HORAS)
+ ", a diferença é de " + falta.format ( FORMATO_HORAS)
+ "." ) ;
}
public static void main
( String [ ] args
) { LocalTime agora = LocalTime.now ( ) ;
mostrar( agora, "07:30" ) ;
mostrar( LocalTime.of ( 5 , 30 ) , "07:30" ) ;
mostrar( LocalTime.of ( 7 , 10 ) , "07:30" ) ;
mostrar( LocalTime.of ( 0 , 0 ) , "07:30" ) ;
mostrar( LocalTime.of ( 7 , 0 ) , "07:30" ) ;
mostrar( LocalTime.of ( 7 , 30 ) , "07:30" ) ;
mostrar( LocalTime.of ( 7 , 31 ) , "07:30" ) ;
mostrar( LocalTime.of ( 10 , 0 ) , "07:30" ) ;
mostrar( LocalTime.of ( 19 , 30 ) , "07:30" ) ;
mostrar( LocalTime.of ( 23 , 59 ) , "07:30" ) ;
mostrar( LocalTime.of ( 0 , 0 ) , "23:59" ) ;
mostrar( LocalTime.of ( 23 , 59 ) , "00:00" ) ;
}
}
aW1wb3J0IGphdmEudGltZS5Mb2NhbFRpbWU7CmltcG9ydCBqYXZhLnRpbWUuZm9ybWF0LkRhdGVUaW1lRm9ybWF0dGVyOwppbXBvcnQgamF2YS50aW1lLmZvcm1hdC5SZXNvbHZlclN0eWxlOwoKY2xhc3MgVGVzdGVEYXRhcyB7CiAgICBwcml2YXRlIHN0YXRpYyBmaW5hbCBEYXRlVGltZUZvcm1hdHRlciBGT1JNQVRPX0hPUkFTID0gRGF0ZVRpbWVGb3JtYXR0ZXIKICAgICAgICAgICAgLm9mUGF0dGVybigiSEg6bW0iKQogICAgICAgICAgICAud2l0aFJlc29sdmVyU3R5bGUoUmVzb2x2ZXJTdHlsZS5TVFJJQ1QpOwoKICAgIHByaXZhdGUgc3RhdGljIExvY2FsVGltZSBmYWx0YW5kbyhMb2NhbFRpbWUgYWdvcmEsIExvY2FsVGltZSBkZXNlamFkYSkgewogICAgICAgIHJldHVybiBkZXNlamFkYS5taW51c0hvdXJzKGFnb3JhLmdldEhvdXIoKSkubWludXNNaW51dGVzKGFnb3JhLmdldE1pbnV0ZSgpKTsKICAgIH0KCiAgICBwcml2YXRlIHN0YXRpYyB2b2lkIG1vc3RyYXIoTG9jYWxUaW1lIGhvcmFyaW8sIFN0cmluZyBvYmpldGl2bykgewogICAgICAgIExvY2FsVGltZSBkZXNlamFkYSA9IExvY2FsVGltZS5wYXJzZShvYmpldGl2bywgRk9STUFUT19IT1JBUyk7CiAgICAgICAgTG9jYWxUaW1lIGZhbHRhID0gZmFsdGFuZG8oaG9yYXJpbywgZGVzZWphZGEpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigKICAgICAgICAJICAgICJFbnRyZSAiICsgaG9yYXJpby5mb3JtYXQoRk9STUFUT19IT1JBUykKICAgICAgICAgICAgICAgICsgIiBlICIgKyBkZXNlamFkYS5mb3JtYXQoRk9STUFUT19IT1JBUykKICAgICAgICAgICAgICAgICsgIiwgYSBkaWZlcmVuw6dhIMOpIGRlICIgKyBmYWx0YS5mb3JtYXQoRk9STUFUT19IT1JBUykKICAgICAgICAgICAgICAgICsgIi4iKTsKICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgTG9jYWxUaW1lIGFnb3JhID0gTG9jYWxUaW1lLm5vdygpOwogICAgICAgIG1vc3RyYXIoYWdvcmEsICIwNzozMCIpOwogICAgICAgIG1vc3RyYXIoTG9jYWxUaW1lLm9mKCA1LCAzMCksICIwNzozMCIpOwogICAgICAgIG1vc3RyYXIoTG9jYWxUaW1lLm9mKCA3LCAxMCksICIwNzozMCIpOwogICAgICAgIG1vc3RyYXIoTG9jYWxUaW1lLm9mKCAwLCAgMCksICIwNzozMCIpOwogICAgICAgIG1vc3RyYXIoTG9jYWxUaW1lLm9mKCA3LCAgMCksICIwNzozMCIpOwogICAgICAgIG1vc3RyYXIoTG9jYWxUaW1lLm9mKCA3LCAzMCksICIwNzozMCIpOwogICAgICAgIG1vc3RyYXIoTG9jYWxUaW1lLm9mKCA3LCAzMSksICIwNzozMCIpOwogICAgICAgIG1vc3RyYXIoTG9jYWxUaW1lLm9mKDEwLCAgMCksICIwNzozMCIpOwogICAgICAgIG1vc3RyYXIoTG9jYWxUaW1lLm9mKDE5LCAzMCksICIwNzozMCIpOwogICAgICAgIG1vc3RyYXIoTG9jYWxUaW1lLm9mKDIzLCA1OSksICIwNzozMCIpOwogICAgICAgIG1vc3RyYXIoTG9jYWxUaW1lLm9mKCAwLCAgMCksICIyMzo1OSIpOwogICAgICAgIG1vc3RyYXIoTG9jYWxUaW1lLm9mKDIzLCA1OSksICIwMDowMCIpOwogICAgfQp9
stdout
Entre 01:02 e 07:30, a diferença é de 06:28.
Entre 05:30 e 07:30, a diferença é de 02:00.
Entre 07:10 e 07:30, a diferença é de 00:20.
Entre 00:00 e 07:30, a diferença é de 07:30.
Entre 07:00 e 07:30, a diferença é de 00:30.
Entre 07:30 e 07:30, a diferença é de 00:00.
Entre 07:31 e 07:30, a diferença é de 23:59.
Entre 10:00 e 07:30, a diferença é de 21:30.
Entre 19:30 e 07:30, a diferença é de 12:00.
Entre 23:59 e 07:30, a diferença é de 07:31.
Entre 00:00 e 23:59, a diferença é de 23:59.
Entre 23:59 e 00:00, a diferença é de 00:01.