Skip to content

Commit e6cc18f

Browse files
authored
Merge pull request mouredev#2660 from AChapeton/main
#14 - TypeScript & JavaScript
2 parents 9aa416c + 6ab108a commit e6cc18f

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const currentDate = new Date();
2+
console.log(currentDate);
3+
4+
const birthDate = new Date(1997, 5, 2, 13, 30, 0);
5+
console.log(birthDate);
6+
7+
const getYearsBetweenDates = function (birthDate, currentDate) {
8+
if (currentDate === void 0) { currentDate = new Date(); }
9+
const birthTime = new Date(birthDate).getTime();
10+
const currentTime = new Date(currentDate).getTime();
11+
const age = (currentTime - birthTime) / (365 * 24 * 60 * 60 * 1000);
12+
return Math.floor(age);
13+
};
14+
15+
console.log(getYearsBetweenDates(birthDate));
16+
17+
18+
const days = ['Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado'];
19+
const months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];
20+
const isLeapYear = function (y) { return y % 4 === 0 && y % 100 !== 0 || y % 400 === 0; };
21+
const daysInAYear = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
22+
23+
// DIFICULTAD EXTRA
24+
console.log('Dia, mes, y año: ', birthDate.getDay() + 1, '/', months[birthDate.getMonth()], '/', birthDate.getFullYear());
25+
console.log('Hora, minuto y segundo: ', 'Hora: ', birthDate.getHours(), ' Minutos: ', birthDate.getMinutes(), ' Segundos: ', birthDate.getSeconds());
26+
console.log('Dia de la semana: ', (birthDate.getDay() > 7) ? days[birthDate.getDay() - 7] : days[birthDate.getDay()]);
27+
console.log('Nombre del mes: ', months[birthDate.getMonth()]);
28+
console.log('Año: ', birthDate.getFullYear());
29+
console.log('Version ingles: ', birthDate.toDateString());
30+
function dayOfYear(date) {
31+
const d = new Date(date);
32+
const daysGiven = d.getDate();
33+
const month = d.getMonth();
34+
const year = d.getFullYear();
35+
if (isLeapYear(year) && month > 1) {
36+
return daysInAYear.slice(0, month).reduce(function (a, c) { return a + c; }, 0) + 1 + daysGiven;
37+
}
38+
else {
39+
return daysInAYear.slice(0, month).reduce(function (a, c) { return a + 1; }, 0) + daysGiven;
40+
}
41+
}
42+
console.log('Dia de año: ', dayOfYear("06/02/2020"));
43+
console.log('Fecha completa: ', birthDate.getDay() + 1, ' de ', months[birthDate.getMonth()], ' de ', birthDate.getFullYear());
44+
console.log('Mes/Dia/Año: ', birthDate.toLocaleDateString());
45+
console.log('Formato Tiempo 12 horas: ', birthDate.toLocaleTimeString());
46+
console.log('Formato Tiempo 24 horas: ', birthDate.toTimeString());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const currentDate: Date = new Date()
2+
console.log(currentDate)
3+
const birthDate: Date = new Date(1997, 5, 2, 13, 30, 0)
4+
console.log(birthDate)
5+
6+
const getYearsBetweenDates = (birthDate: Date, currentDate:Date = new Date()) => {
7+
const birthTime = new Date(birthDate).getTime()
8+
const currentTime = new Date(currentDate).getTime()
9+
const age = (currentTime - birthTime) / (365 * 24 * 60 * 60 * 1000)
10+
return Math.floor(age)
11+
}
12+
13+
console.log(getYearsBetweenDates(birthDate))
14+
15+
const days = ['Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado']
16+
const months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']
17+
18+
const isLeapYear = y => y % 4 === 0 && y % 100 !== 0 || y % 400 === 0;
19+
const daysInAYear = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
20+
21+
22+
// DIFICULTAD EXTRA
23+
console.log('Dia, mes, y año: ', birthDate.getDay() + 1, '/', months[birthDate.getMonth()], '/', birthDate.getFullYear())
24+
console.log('Hora, minuto y segundo: ', 'Hora: ', birthDate.getHours(), ' Minutos: ', birthDate.getMinutes(), ' Segundos: ', birthDate.getSeconds())
25+
console.log('Dia de la semana: ', (birthDate.getDay() > 7) ? days[birthDate.getDay() - 7] : days[birthDate.getDay()])
26+
console.log('Nombre del mes: ', months[birthDate.getMonth()])
27+
console.log('Año: ', birthDate.getFullYear())
28+
console.log('Version ingles: ', birthDate.toDateString())
29+
30+
function dayOfYear ( date ) {
31+
const d = new Date(date);
32+
const daysGiven = d.getDate();
33+
const month = d.getMonth();
34+
const year = d.getFullYear();
35+
36+
if ( isLeapYear(year) && month > 1) {
37+
return daysInAYear.slice(0, month).reduce( (a, c) => a + c, 0) + 1 + daysGiven;
38+
} else {
39+
return daysInAYear.slice(0, month).reduce( (a, c) => a + 1, 0) + daysGiven;
40+
}
41+
}
42+
43+
console.log('Dia de año: ', dayOfYear("06/02/2020"))
44+
console.log('Fecha completa: ', birthDate.getDay() + 1, ' de ', months[birthDate.getMonth()], ' de ', birthDate.getFullYear())
45+
console.log('Mes/Dia/Año: ', birthDate.toLocaleDateString())
46+
console.log('Formato Tiempo 12 horas: ', birthDate.toLocaleTimeString())
47+
console.log('Formato Tiempo 24 horas: ', birthDate.toTimeString())

0 commit comments

Comments
 (0)