Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hygull/5ae2f0dbef5331a0b6d7e6dc4bc20f92 to your computer and use it in GitHub Desktop.
Conversion of a simple Month Year string to short form

An Illustration

> function getDateShortName(s, shortYear=true) {
...     let parts = s.split(/\s+/ig)
...     
...     if(shortYear) {
.....         return parts[0].slice(0, 3) + '\'' + parts[1].slice(2)
.....     } else {
.....         return parts[0].slice(0, 3) + '\'' + parts[1]
.....     }
... }
undefined
> 
> getDateShortName("January 2020")
"Jan'20"
> 
> getDateShortName("January 2020", false)
"Jan'2020"
> 
> getDateShortName("February  2021")
"Feb'21"
> 
> getDateShortName("February  2021", false)
"Feb'2021"
> 
> getDateShortName("February  2021", true)
"Feb'21"
> 
> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment