V
V
Vincent Moro2020-02-25 18:08:50
JavaScript
Vincent Moro, 2020-02-25 18:08:50

Who faced the problem in platformio-ide-terminal?

5e55383dceaf3327273737.pngan empty terminal appears, with a blinking cursor, I can not configure it correctly. The version is the latest, it is impossible to add text to the terminal.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2019-07-04
@fapchat

// why this zero?
To get not 3 minutes, but 03, someone "smart" came up with the idea of ​​​​adding a zero at the beginning, and then taking the last two characters.
Could it be replaced with x<10 ? '0' + x : x
// Like 3 first and 3 last elements of array d. What for?
well, like year.month.day hh:mm:ss
But better throw this garbage away and learn how to use Intl.DateTimeFormat

A
Anton Spirin, 2019-07-04
@rockon404

Learning simple debugging. We display the places of interest in the console:

function formatDate(date) {
  /* код без изменений */  
 
  let d = date;

  const dWithoutZeros = [
    d.getDate(),
    (d.getMonth() + 1),
    d.getFullYear(),
    d.getHours(),
    d.getMinutes()
  ];

  console.log('d[]: ', dWithoutZeros);

  d = [
    '0' + d.getDate(),
    '0' + (d.getMonth() + 1),
    '' + d.getFullYear(),
    '0' + d.getHours(),
    '0' + d.getMinutes()
  ];
  
  console.log('d[] with zeros: ', d);
  
  d = d.map(component => component.slice(-2));
  
  console.log('d[] sliced: ', d);
  
  const a = d.slice(0, 3).join('.');
  
  console.log('part a: ', a);
  
  const b = d.slice(3).join(':');
  
  console.log('part b: ', b);
  
  const result = a + ' ' + b;
  
  console.log('result: ', result);
  
  return result;
}

/* код без изменений */

Let's run it and see the output. All but one question is gone.
Open jsfiddle. We type:
console.log('case 1: ', new Date - 1);
console.log('case 2: ', new Date(new Date - 1));

Let's run it and see the output. We draw conclusions. Just in case , read MDN .
Congratulations, you've learned how to debug using the console, and also learned about the existence of MDN, and if you ever have similar questions, you now know how to answer them yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question