Skip to content

Instantly share code, notes, and snippets.

@19h
Created June 27, 2013 13:34
Show Gist options
  • Select an option

  • Save 19h/5876448 to your computer and use it in GitHub Desktop.

Select an option

Save 19h/5876448 to your computer and use it in GitHub Desktop.
Consensus Stamp Format (V8-ECMA) (Javascript)
/*
Consensus Stamp Format
<Day> / <Month in Quarter>:Q<Quarter> / <Years since 1970>
27th June, 2013 <> 27/3:Q2/43.
*/
toCSF = function (v) {
!(v instanceof Date) && (v=new Date(v));
var m = v.getMonth()+1;
var Q = ((m/3)-.1|0)+1;
var mQ = 3-((Q*3)-m);
return v.getDate()+"/"+mQ+":Q"+Q+"/"+(-70+v.getYear())
}
fromCSF = function (v) {
v=v.split("/"); v[1]=v[1].split(":Q");
return new Date(((+v[1][0])+3*(+v[1][1])-3)+"/"+v[0]+"/"+(1970+(+v[2])))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment