CHunky Universe of Vigourous Astonishing SHarepoint :)

Tag Archives: date

Chuvash localization of moment.js

For three months ago I added Chuvash localization of moment.js. For 16 days ago moment.js 1.7.0 was officially released which included the Chuvash translation.

Wait a sec… What is moment.js?

moment.js is the best datetime tool for javascript. It supports many languages (now even Chuvash) for displaying date and time. Another very handy functionality is showing relative time which has a simple interface: fromNow().

Here is a simple example from a web browser console:

moment().subtract("days", 3).calendar()
//"Иртнĕ вырсарникун 07:30 сехетре"
moment().subtract("days", 3).subtract("hours", 10).calendar()
//"Иртнĕ шăматкун 21:31 сехетре"
moment("2011-10-04", "YYYY-MM-DD").fromNow()
//"10 уйăх каялла"
moment("2012-10-04", "YYYY-MM-DD").fromNow()
//"2 уйăхран"

Previous Issues

UPDATE: It has been released an update of moment.js: 1.7.1 where all of the issues with Chuvash localization are gone.
For Until now there is was one issue with Chuvash localization of moment.js: wrong suffix in future relative time. In most supported languages in moment.js to express something what will happen in future, prepositions (words before, like in, for, by) are used. In the agglunative languages (Basque, Turkish, Korean and Japanese) postpositions (words after) are used. Chuvash is a bit different, the future is expressed by the ablative case.

ikĕ ujăh (2 months) - ikĕ ujăhran (in two months)

Not a big deal, you think? It wouldn’t be if it there wasn’t vowel harmony (front and back vowels):

ikĕ sehet (2 hours) - ikĕ sehetren (in two hours)

Besides vowel harmony the ablative case affix can be ran/ren (after almost all sounds) and tan/ten (after l n r).

ikĕ şul (2 years) - ikĕ şultan (in two years)

For now it is not possible to provide a function for custom logic for future fromNow (like there is such functions for time units: minutes, montsh, years), something like that:

relativeTime : {
	future : function(output) {
		var affix = /сехет$/i.exec(output) 
                     ? "рен" : /çул$/i.exec(output) ? "тан" : "ран";
		return output + affix; 

And the “humanize” function in moment.js has to be able to handle a function as parameter:

humanize : function (withSuffix) {
	var difference = +this,
		rel = this.lang().relativeTime,
		output = relativeTime(difference, !withSuffix, this.lang());
	if (withSuffix) {
		var rt = difference <= 0 ? rel.past : rel.future;
                //was: output = (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output);
		if (typeof rt === 'function') {
			output = rt(output);
		else {
			output = rt.replace(/%s/i, output);
	return output;

moment.js – the best javascript tool for working with dates

Just look at moment.js. Everybody who have worked with dates in javascript are going to love it.

Kalendae – new javascript utility for calendars

An alternative to jQuery UI datepicker is Kalendae. (MIT License). Highly customizable and no dependencies to other javascript libraries.

Here is the highlights:

Kalendae is an attempt to do something that nobody has yet been able to do: make a date picker that doesn’t suck. Kalendae provides the following features:

  1. Fully portable, no dependencies. No jQuery, no Prototype, no MooTools; just add the script and the stylesheet and you’re good to go.
  2. Fully and easily skinable. The default theme uses only one image file (a mask for the previous and next buttons), everything else is styled using CSS.
  3. Supports all modern browsers and IE8.
  4. Support single day, multiple day, or day range selection.
  5. Configurable number of months to be displayed at once.
  6. Can be displayed on the page as an inline widget, or attached to one or more input fields as a popup control.
  7. Can be attached to any page element, not just named elements.
  8. Configurable blackouts, defined either as an array of dates or via a callback function
  9. Output selected dates in a variety of formats
  10. Leverages moment.js for smart and easy date parsing.

Found through daily.js

format javascript date in ISO 8601

There is a solution in StackOverflow:

/* use a function for the exact format desired... */
function ISODateString(d){
 function pad(n){return n<10 ? '0'+n : n}
 return d.getUTCFullYear()+'-'
      + pad(d.getUTCMonth()+1)+'-'
      + pad(d.getUTCDate())+'T'
      + pad(d.getUTCHours())+':'
      + pad(d.getUTCMinutes())+':'
      + pad(d.getUTCSeconds())+'Z'}

var d = new Date();
print(ISODateString(d)); // prints something like 2009-09-28T19:03:12Z

But there is already a function for this: toISOString, it came with ecmascript 5. Unfortunately, not all browsers support this, to solve this problem, we can provide our own prototype function for Date if it doesn’t exist:

if (!Date.prototype.toISOString) {
    Date.prototype.toISOString = function() {
        function pad(n) { return n < 10 ? '0' + n : n }
        return this.getUTCFullYear() + '-'
            + pad(this.getUTCMonth() + 1) + '-'
                + pad(this.getUTCDate()) + 'T'
                    + pad(this.getUTCHours()) + ':'
                        + pad(this.getUTCMinutes()) + ':'
                            + pad(this.getUTCSeconds()) + 'Z';

By the way, if you want to create an ISO string of DateTime in C#, use ToString(“s”):

var today = DateTime.Today;
var monthAgo = today.AddDays(-30);
var t = monthAgo.ToString("s");

Another way to convert a javascript date to ISO is to use JSON.stringify. The difference is that you get the date in ISO format surrounded with quotation marks. The curious thing is that Sys.Serialization.JavaScriptSerializer.serialize should do the same, but it returns the date in different format:

So it is the same date. Actually there is a deserialize function, too:


But why does the date look like “”\/Date(1326234740861)\/””. But when we get objects from an ajax call, we just get: “/Date(1326234740861)/”. The explanation must be in the deserialization inside $.ajax.

Parse Dates From ISO 8601

What if you want to create a date from iso in javascript. It is no problem if you use modern browsers:

var date = new Date(isoString);

But not in IE. Here it fails. So we have to create custom parsing functions for that. D-oh. (One solution could be to use moment.js):

Date.fromISOString = function (iso) {
    ///<summary>Is used to parse iso 8601 dates in IE
    ///partly inspired from
    var date = new Date(iso);
    if (isNaN(date)) {
        var minutesOffset = 0, numericKeys = [1, 4, 5, 6, 7, 10, 11];
        var struct = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/ .exec(iso);
        // avoid NaN timestamps caused by “undefined” values being passed to Date.UTC
        for (var i = 0, k; (k = numericKeys[i]); ++i) {
            struct[k] = +struct[k] || 0;

        // allow undefined days and months
        struct[2] = (+struct[2] || 1) - 1;
        struct[3] = +struct[3] || 1;

        if (struct[8] !== 'Z' && struct[9] !== undefined) {
            minutesOffset = struct[10] * 60 + struct[11];

            if (struct[9] === '+') {
                minutesOffset = 0 - minutesOffset;
        var s = Date.UTC(struct[1], struct[2], struct[3], struct[4], struct[5] + minutesOffset, struct[6], struct[7]);
        date = new Date(s);
    return date;
Daniel Chronlund Cloud Tech Blog

News, tips and thoughts for Microsoft cloud fans

Вула Чăвашла

VulaCV - Чăвашла вулаттаракан сайт

Discovering SharePoint

And going crazy doing it

Bram de Jager - Architect, Speaker, Author

Microsoft 365, SharePoint and Azure

SharePoint Dragons

Nikander & Margriet on SharePoint

Mai Omar Desouki

PFE @ Microsoft

Cameron Dwyer

Office 365, SharePoint, Azure, OnePlace Solutions & Life's Other Little Wonders


Me and My doings!

Share SharePoint Points !

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

Aryan Nava

DevOps, Cloud and Blockchain Consultant


SharePoint for everyone


Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint


Mostly what I know and share about...