Skip to content

Instantly share code, notes, and snippets.

@eyecatchup
Last active February 26, 2017 21:00
Show Gist options
  • Select an option

  • Save eyecatchup/63e5abc34153c1ad31ec31f3f2475a08 to your computer and use it in GitHub Desktop.

Select an option

Save eyecatchup/63e5abc34153c1ad31ec31f3f2475a08 to your computer and use it in GitHub Desktop.
var AndroidBuildstringConverter = {
DayZero: new Date(2009, 0, 1),
ReleaseNames: "Astro Boy;Bender;Petit Four;Cupcake;Donut;Eclair;Froyo;Gingerbread;" +
"Honeycomb;Ice Cream Sandwich;Jelly Bean;KitKat;Lollipop;Marshmallow;Nougat",
getBuilddateByString: function (b) {
if ("string" !== typeof b || !b.length) {
return console.log("Invalid input. String required, got " + typeof b),
!1;
}
var c = this.ReleaseNames.split(";").pop()[0],
e = {};
if (b[0].toUpperCase() > c || "C" > b[0].toUpperCase()) {
return console.log("Invalid build string. 1st char must be between C and " + c),
!1;
}
var c = this.ReleaseNames.split(";");
for (var d in c.reverse()) {
if (b[0].toUpperCase() == c[d][0].toUpperCase()) {
e.releaseName = c[d];
break;
}
}
if ("P" !== b[1].toUpperCase() && "R" !== b[1].toUpperCase()) {
return console.log("Invalid build string. 2nd char must be either R (Release) or P (Preview). Got " + b[1].toUpperCase()),
!1;
}
e.buildBranch = "R" === b[1].toUpperCase()
? "Release"
: "Preview";
console.dir(e);
return e;
},
getBuildstringByDate: function (b, c) {
var e = this.ReleaseNames.split(";").pop()[0],
e = e + (!1 === c
? "P"
: "R");
c = /object Date/.test(Object.prototype.toString.call(b))
? b
: "string" === typeof b && b.length
? new Date(Date.parse(b + " UTC+0000"))
: new Date;
for (var d = this.DayZero, d = 12 * (c.getUTCFullYear() - d.getUTCFullYear()) + (c.getUTCMonth() - d.getUTCMonth()) + 1, d = Math.round(d / 3); 26 < d;) {
d -= 26;
}
e += String.fromCharCode(64 + d);
m = c.getUTCMonth();
m = 3 < m
? 9 <= m
? 9
: 6 <= m
? 6
: 3
: 0;
m = new Date(c.getUTCFullYear(), m, 1);
return e + ("" + (Math.floor((c - m) / 86400000) + 1));
}
};
var a = AndroidBuildstringConverter.getBuilddateByString('NPG05');
console.dir(a);
var a = AndroidBuildstringConverter.getBuildstringByDate(); // Today's build string
console.dir(a);
a = AndroidBuildstringConverter.getBuildstringByDate(null, false); // Today's build string; but for Preview builds
console.dir(a);
var dt = new Date(2017, 0, 11); // Optionally, pass a JavaScript Date object to specify a date.
a = AndroidBuildstringConverter.getBuildstringByDate(dt); // Build string for Apr 11th 2017
console.dir(a);
dt = '2017/1/11'; // Or, instead of a Date object, you can also pass a string.
a = AndroidBuildstringConverter.getBuildstringByDate(dt); // Build string for Apr 11th 2017
console.dir(a);
dt = '2017-01-11'; // String format is 'flexible', btw. So no need to format yourself.
a = AndroidBuildstringConverter.getBuildstringByDate(dt); // Build string for Apr 11th 2017
console.dir(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment