jhcloos.github.io icon indicating copy to clipboard operation
jhcloos.github.io copied to clipboard

removed years on copyright

Open phoebe-leong opened this issue 2 years ago • 8 comments

the copyright will still be valid, and you won't need to keep on updating the year

phoebe-leong avatar Oct 05 '21 22:10 phoebe-leong

If we use a little bit of JavaScript, we can make the year dynamic.

const date = new Date()
const year = date.getUTCFullYear() // this gives you the current year
const text = `Copyright © 2004 - ${year}`

jsstrn avatar Oct 11 '21 23:10 jsstrn

Oh that'd be cool

phoebe-leong avatar Oct 11 '21 23:10 phoebe-leong

Couldn't it be simplified to

const date = new Date()
const text = `Copyright © 2004 - ${date.getUTCFullYear()}`

I don't know much Javascript, so please correct me if I'm wrong

phoebe-leong avatar Oct 11 '21 23:10 phoebe-leong

That would depend on what we mean by "simplified."

For instance, we could write our solution like this

const text = `Copyright © 2004 - ${(new Date()).getUTCFullYear()}`

This fits into one line, but is it simplified? 🤷🏽

Perhaps a better way to think of writing code is its ease of readability for humans. Consider the next example,

const date = new Date()
const currentYear = date.getUTCFullYear()

const text = `Copyright © 2004 - ${currentYear}`

While there is a lot more code to read, we might say that it's actually easier to read. This is a matter of style, since both code examples work perfectly.

Though this is a trivial example, you can imagine a complex codebase might contain thousands of lines of code. In such a scenario, it makes a big difference when code is written in a clear and concise manner.

Hope that helps!

jsstrn avatar Oct 12 '21 07:10 jsstrn

Hmm. You seem like a smart person, I think I'll add your suggestion

phoebe-leong avatar Oct 12 '21 08:10 phoebe-leong

Thanks 👍 for polling

stanabshub avatar Nov 03 '21 08:11 stanabshub