Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@sunitJindal
sunitJindal / JavascriptSample.js
Created June 21, 2017 07:31
Sample code snippets of Javascript
(function closureExample() {
// Closure
function a() {
var b = 10;
return function c(d){
return b+d;
}
}
* https://auth0.com/blog/what-is-and-how-does-single-sign-on-work/
* https://www.ru.nl/publish/pages/769526/z_researchpaper_sso_final_nick_heijmink_s4250559.pdf
@sunitJindal
sunitJindal / tz-mapping.js
Created January 20, 2016 14:24
Time zone name mapping, to make zone names more user friendly
var tzMap = {
"Afghanistan (Kabul)": "Asia/Kabul",
"Alaska Time": "US/Alaska",
"Atlantic Time": "Brazil/West",
"Atlantic Time (Bermuda)": "Atlantic/Bermuda",
"Australian Central Time (Adelaide)": "Australia/Adelaide",
"Australian Central Time (Northern Territory)": "Australia/North",
"Australian Eastern Time (Queensland)": "Australia/Queensland",
"Australian Eastern Time (Sydney)": "Australia/Sydney",
"Australian Western Time": "Australia/West",
@sunitJindal
sunitJindal / date-string-to-moment.js
Created January 20, 2016 10:15
Right way to convert date string into moment, with proper UTC offset value
// date string with time zone. Apply UTC offset after moment is created
// without applying UTC offset, the format() method will return hours and date formated as per local time
moment("14/03/2016 +0130","DD/MM/YYYY Z").utcOffset("+0130")
@sunitJindal
sunitJindal / date-timezone.js
Last active January 20, 2016 09:47
Conversion of date string to date object using Moment.js
// Local time zone is Asia/Kolkata with offset GMT +0530
var dt = "14/03/2016";
var dtz = "14/03/2016 +0130";
var tz = "+0130";
var df = "DD/MM/YYYY";
var dfz = "DD/MM/YYYY Z";
var d1 = moment(dtz,dfz); // date string with time zone
var d2 = moment(dt,df); // date string without timezone