Skip to content

Commit

Permalink
Merge pull request #2660 from AChapeton/main
Browse files Browse the repository at this point in the history
#14 - TypeScript & JavaScript
  • Loading branch information
Roswell468 authored Apr 2, 2024
2 parents 9aa416c + 6ab108a commit e6cc18f
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Roadmap/14 - FECHAS/javascript/AChapeton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const currentDate = new Date();
console.log(currentDate);

const birthDate = new Date(1997, 5, 2, 13, 30, 0);
console.log(birthDate);

const getYearsBetweenDates = function (birthDate, currentDate) {
if (currentDate === void 0) { currentDate = new Date(); }
const birthTime = new Date(birthDate).getTime();
const currentTime = new Date(currentDate).getTime();
const age = (currentTime - birthTime) / (365 * 24 * 60 * 60 * 1000);
return Math.floor(age);
};

console.log(getYearsBetweenDates(birthDate));


const days = ['Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado'];
const months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];
const isLeapYear = function (y) { return y % 4 === 0 && y % 100 !== 0 || y % 400 === 0; };
const daysInAYear = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

// DIFICULTAD EXTRA
console.log('Dia, mes, y año: ', birthDate.getDay() + 1, '/', months[birthDate.getMonth()], '/', birthDate.getFullYear());
console.log('Hora, minuto y segundo: ', 'Hora: ', birthDate.getHours(), ' Minutos: ', birthDate.getMinutes(), ' Segundos: ', birthDate.getSeconds());
console.log('Dia de la semana: ', (birthDate.getDay() > 7) ? days[birthDate.getDay() - 7] : days[birthDate.getDay()]);
console.log('Nombre del mes: ', months[birthDate.getMonth()]);
console.log('Año: ', birthDate.getFullYear());
console.log('Version ingles: ', birthDate.toDateString());
function dayOfYear(date) {
const d = new Date(date);
const daysGiven = d.getDate();
const month = d.getMonth();
const year = d.getFullYear();
if (isLeapYear(year) && month > 1) {
return daysInAYear.slice(0, month).reduce(function (a, c) { return a + c; }, 0) + 1 + daysGiven;
}
else {
return daysInAYear.slice(0, month).reduce(function (a, c) { return a + 1; }, 0) + daysGiven;
}
}
console.log('Dia de año: ', dayOfYear("06/02/2020"));
console.log('Fecha completa: ', birthDate.getDay() + 1, ' de ', months[birthDate.getMonth()], ' de ', birthDate.getFullYear());
console.log('Mes/Dia/Año: ', birthDate.toLocaleDateString());
console.log('Formato Tiempo 12 horas: ', birthDate.toLocaleTimeString());
console.log('Formato Tiempo 24 horas: ', birthDate.toTimeString());
47 changes: 47 additions & 0 deletions Roadmap/14 - FECHAS/typescript/AChapeton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const currentDate: Date = new Date()
console.log(currentDate)
const birthDate: Date = new Date(1997, 5, 2, 13, 30, 0)
console.log(birthDate)

const getYearsBetweenDates = (birthDate: Date, currentDate:Date = new Date()) => {
const birthTime = new Date(birthDate).getTime()
const currentTime = new Date(currentDate).getTime()
const age = (currentTime - birthTime) / (365 * 24 * 60 * 60 * 1000)
return Math.floor(age)
}

console.log(getYearsBetweenDates(birthDate))

const days = ['Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado']
const months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']

const isLeapYear = y => y % 4 === 0 && y % 100 !== 0 || y % 400 === 0;
const daysInAYear = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];


// DIFICULTAD EXTRA
console.log('Dia, mes, y año: ', birthDate.getDay() + 1, '/', months[birthDate.getMonth()], '/', birthDate.getFullYear())
console.log('Hora, minuto y segundo: ', 'Hora: ', birthDate.getHours(), ' Minutos: ', birthDate.getMinutes(), ' Segundos: ', birthDate.getSeconds())
console.log('Dia de la semana: ', (birthDate.getDay() > 7) ? days[birthDate.getDay() - 7] : days[birthDate.getDay()])
console.log('Nombre del mes: ', months[birthDate.getMonth()])
console.log('Año: ', birthDate.getFullYear())
console.log('Version ingles: ', birthDate.toDateString())

function dayOfYear ( date ) {
const d = new Date(date);
const daysGiven = d.getDate();
const month = d.getMonth();
const year = d.getFullYear();

if ( isLeapYear(year) && month > 1) {
return daysInAYear.slice(0, month).reduce( (a, c) => a + c, 0) + 1 + daysGiven;
} else {
return daysInAYear.slice(0, month).reduce( (a, c) => a + 1, 0) + daysGiven;
}
}

console.log('Dia de año: ', dayOfYear("06/02/2020"))
console.log('Fecha completa: ', birthDate.getDay() + 1, ' de ', months[birthDate.getMonth()], ' de ', birthDate.getFullYear())
console.log('Mes/Dia/Año: ', birthDate.toLocaleDateString())
console.log('Formato Tiempo 12 horas: ', birthDate.toLocaleTimeString())
console.log('Formato Tiempo 24 horas: ', birthDate.toTimeString())

0 comments on commit e6cc18f

Please sign in to comment.