Skip to content

Instantly share code, notes, and snippets.

@abdullahoguk
Last active September 29, 2021 08:34
Show Gist options
  • Save abdullahoguk/d26e07292bd58e9936fc0d43fa41d429 to your computer and use it in GitHub Desktop.
Save abdullahoguk/d26e07292bd58e9936fc0d43fa41d429 to your computer and use it in GitHub Desktop.
Time Ago JavaScript Function in Turkish
/*
Tiny time ago JS function localized into Turkish
SOURCE:
https://github.com/odyniec/tinyAgo-js
*/
/*------------- USAGE --------------------*/
ago(new Date("2021-09-26"))
/*3 gün önce*/
/*------------- minified ----------------*/
function ago(a){a=0|(Date.now()-a)/1e3;var n,e,o={saniye:60,dakika:60,saat:24,"gün":7,hafta:4.35,ay:12,"yıl":1e4};for(n in o)if(e=a%o[n],!(a=0|a/o[n]))return e<0?-1*e+" "+n+" sonra":e+" "+n+" önce"}
/*------------- Beautified ---------------*/
function ago(val) {
val = 0 | (Date.now() - val) / 1000;
var unit, length = { "saniye": 60, "dakika": 60, "saat": 24, "gün": 7, "hafta": 4.35,
"ay": 12, "yıl": 10000 }, result;
for (unit in length) {
result = val % length[unit];
if (!(val = 0 | val / length[unit]))
return result < 0 ? result*(-1) + ' ' + unit + ' sonra' : result + ' ' + unit + ' önce';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment