Skip to content

Commit d1ff781

Browse files
committed
Resolución Reto #48 y enunciado Reto #49
1 parent f998816 commit d1ff781

File tree

3 files changed

+120
-1
lines changed

3 files changed

+120
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ Tienes toda la información extendida sobre los retos de programación semanales
8181
* **#46** - 14/11/22 - [`¿DÓNDE ESTÁ EL ROBOT?`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge46.kt)
8282
* **#47** - 21/11/22 - [`VOCAL MÁS COMÚN`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge47.kt)
8383
* **#48** - 28/11/22 - [`EL CALENDARIO DE ADEVIENTO 2022`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge48.kt)
84-
* **#49** - 05/12/22 - `Publicación nuevo reto...`
84+
* **#49** - 05/12/22 - [`EL DETECTOR DE HANDLES`](https://github.com/mouredev/Weekly-Challenge-2022-Kotlin/blob/main/app/src/main/java/com/mouredev/weeklychallenge2022/Challenge49.kt)
85+
* **#50** - 12/12/22 - `Publicación nuevo reto...`
8586

8687
<a href="https://youtu.be/ydH_B5KuqGs"><img src="http://i3.ytimg.com/vi/ydH_B5KuqGs/maxresdefault.jpg" style="height: 50%; width:50%;"/></a>
8788

app/src/main/java/com/mouredev/weeklychallenge2022/Challenge48.kt

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package com.mouredev.weeklychallenge2022
22

3+
import java.time.LocalDateTime
4+
import java.time.ZoneId
5+
import java.time.format.DateTimeFormatter
6+
import java.util.Calendar
7+
import java.util.Date
8+
39
/*
410
* Reto #48
511
* EL CALENDARIO DE ADEVIENTO 2022
@@ -27,3 +33,90 @@ package com.mouredev.weeklychallenge2022
2733
* https://retosdeprogramacion.com/semanales2022.
2834
*
2935
*/
36+
37+
fun main() {
38+
39+
// aDEViento2022(LocalDateTime.of(2022, 12, 5, 20, 27, 56).toDate())
40+
41+
val formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")
42+
println(aDEViento2022(LocalDateTime.parse("2022/12/05 20:27:56", formatter).toDate()))
43+
println(aDEViento2022(LocalDateTime.parse("2022/12/01 00:00:00", formatter).toDate()))
44+
println(aDEViento2022(LocalDateTime.parse("2022/12/24 23:59:59", formatter).toDate()))
45+
println(aDEViento2022(LocalDateTime.parse("2022/11/30 23:59:59", formatter).toDate()))
46+
println(aDEViento2022(LocalDateTime.parse("2022/12/25 00:00:00", formatter).toDate()))
47+
println(aDEViento2022(LocalDateTime.parse("2022/10/30 00:00:00", formatter).toDate()))
48+
println(aDEViento2022(LocalDateTime.parse("2022/12/30 04:32:12", formatter).toDate()))
49+
println(aDEViento2022(LocalDateTime.parse("2020/10/30 00:00:00", formatter).toDate()))
50+
println(aDEViento2022(LocalDateTime.parse("2024/12/30 04:32:12", formatter).toDate()))
51+
}
52+
53+
private fun LocalDateTime.toDate(): Date {
54+
return Date.from(this.atZone(ZoneId.systemDefault()).toInstant())
55+
}
56+
57+
private fun aDEViento2022(date: Date): String {
58+
59+
val formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")
60+
val startDate = LocalDateTime.parse("2022/12/01 00:00:00", formatter).toDate()
61+
val endDate = LocalDateTime.parse("2022/12/24 23:59:59", formatter).toDate()
62+
63+
if (date in startDate..endDate) {
64+
65+
val gifts = arrayOf(
66+
"El programador pragmático",
67+
"while True: learn()",
68+
"Aprende Javascript ES9, HTML, CSS3 y NodeJS desde cero",
69+
"Patrones de Diseño en JavaScript y TypeScript",
70+
"Aprende Python en un fin de semana",
71+
"Regalo 6",
72+
"Regalo 7",
73+
"Regalo 8",
74+
"Regalo 9",
75+
"Regalo 10",
76+
"Regalo 11",
77+
"Regalo 12",
78+
"Regalo 13",
79+
"Regalo 14",
80+
"Regalo 15",
81+
"Regalo 16",
82+
"Regalo 17",
83+
"Regalo 18",
84+
"Regalo 19",
85+
"Regalo 20",
86+
"Regalo 21",
87+
"Regalo 22",
88+
"Regalo 23",
89+
"Regalo 24")
90+
91+
val calendar = Calendar.getInstance()
92+
calendar.time = date
93+
calendar.set(Calendar.HOUR_OF_DAY, 23)
94+
calendar.set(Calendar.MINUTE, 59)
95+
calendar.set(Calendar.SECOND, 59)
96+
97+
val day = calendar.get(Calendar.DAY_OF_MONTH)
98+
99+
return "El regalo del día es: ${gifts[day - 1]} y el sorteo del día acaba en: ${diffTimeComponentsText(date, calendar.time)}"
100+
}
101+
102+
val intro = if (date < startDate) "El calendario de aDEViento 2022 comenzará en:" else "El calendario de aDEViento 2022 ha finalizado hace:"
103+
val timeComponents = diffTimeComponentsText(if (date < startDate) date else endDate,
104+
if (date < startDate) startDate else date)
105+
return "$intro $timeComponents"
106+
}
107+
108+
private fun diffTimeComponentsText(startDate: Date, endDate: Date): String {
109+
110+
val diffInMillis = endDate.time - startDate.time
111+
112+
println(diffInMillis)
113+
114+
val second = diffInMillis / 1000L % 60
115+
val minutes = diffInMillis / (1000L * 60) % 60
116+
val hours = diffInMillis / (1000L * 60 * 60) % 24
117+
val days = diffInMillis / (1000L * 60 * 60 * 24) % 365
118+
val years = diffInMillis / (1000L * 60 * 60 * 24 * 365)
119+
120+
return "$years años, $days días, $hours horas, $minutes minutos, $second segundos"
121+
}
122+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.mouredev.weeklychallenge2022
2+
3+
/*
4+
* Reto #49
5+
* EL DETECTOR DE HANDLES
6+
* Fecha publicación enunciado: 05/11/22
7+
* Fecha publicación resolución: 12/12/22
8+
* Dificultad: FÁCIL
9+
*
10+
* Enunciado: Crea una función que sea capaz de detectar y retornar todos los handles de un texto usando solamente Expresiones Regulares.
11+
* Debes crear una expresión regular para cada caso:
12+
* - Handle usuario: Los que comienzan por "@"
13+
* - Handle hashtag: Los que comienzan por "#"
14+
* - Handle web: Los que comienzan por "www.", "http://", "https://" y finalizan con un dominio (.com, .es...)
15+
*
16+
* Información adicional:
17+
* - Usa el canal de nuestro Discord (https://mouredev.com/discord) "🔁reto-semanal"
18+
* para preguntas, dudas o prestar ayuda a la comunidad.
19+
* - Tienes toda la información sobre los retos semanales en
20+
* https://retosdeprogramacion.com/semanales2022.
21+
*
22+
*/
23+
24+
25+

0 commit comments

Comments
 (0)