I assigned the date_work
property to a Date data type. However, when I check the data type using the command
console.log(typeof master.date_work)
, it shows as a string
for some reason. This causes an error when using the getTime()
function. How can I convert the string data type to a Date?
TypeError: master.date_work.getTime is not a function
Model:
export interface Masters {
master_id?: string,
full_name: string,
comment: string,
date_work: Date,
teams_id: string
}
ts:
reports: Rep4Hours[]
masters: Masters[]
teams: Teams[]
filteredTeams = []
filteredMasters = []
onSelectedReport(reportId) {
this.selectedReport = this.reports.find(
el => {
return el.report_id === reportId
}
)
if (this.teamsService) {
this.teamsService.fetch().subscribe(
team => {
this.teams = team
this.filteredTeams = this.teams.filter(
(team) => team.team_id == this.selectedReport.teams_id
)
if (this.mastersService) {
this.mastersService.fetch().subscribe(
master => {
this.filteredMasters = []
this.masters = master
for(let team of this.filteredTeams){
for(let master of this.masters){
if(master.teams_id == team.team_id){
if (Math.max(...this.masters.map(master => master.date_work.getTime()))) {
if (master.date_work <= this.selectedReport.report_date) {
this.filteredMasters.push(master)
}
}
}
}
}
}
)
}
}
)
}
}