User Tools

Site Tools


software:tiddlywiki

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
software:tiddlywiki [2014/04/12 19:11] – created superwizardsoftware:tiddlywiki [2014/04/12 19:27] (current) superwizard
Line 1: Line 1:
 ====== Creating a baby journal with TiddlyWiki 5 ====== ====== Creating a baby journal with TiddlyWiki 5 ======
 +
 +From: http://a-penguin-in-redmond.blogspot.com/2014/02/creating-baby-journal-with-tiddlywiki-5.html
  
 <code> <code>
Line 10: Line 12:
 exports.params = [ { name: "birthDate" }, { name: "currentDate" } ]; exports.params = [ { name: "birthDate" }, { name: "currentDate" } ];
  
-exports.run = function(birthDate, currentDate) { +exports.run = function(birthDate, currentDate) 
-  var getNormalizedDate = function (date, referenceDate) {+
 +    var getNormalizedDate = function (date, referenceDate) {
     var numberOfDaysInMonth = (new Date(date.getFullYear(), date.getMonth()+1, 0)).getDate();     var numberOfDaysInMonth = (new Date(date.getFullYear(), date.getMonth()+1, 0)).getDate();
-    if (numberOfDaysInMonth < referenceDate.getDate()) { +    if (numberOfDaysInMonth < referenceDate.getDate()) 
-      return numberOfDaysInMonth;+    
 +        return numberOfDaysInMonth;
     }     }
-    else { +    else 
-      return referenceDate.getDate();+    
 +        return referenceDate.getDate();
     }     }
-  +
-  var getAgeString = function (birthDate, currentDate) {+var getAgeString = function (birthDate, currentDate) 
 +{
     var tmpBirthDate = new Date(birthDate);     var tmpBirthDate = new Date(birthDate);
     var tmpCurrentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());     var tmpCurrentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());
-    if (tmpCurrentDate < tmpBirthDate) return "not yet born";+    if (tmpCurrentDate < tmpBirthDate) 
 +    ( 
 +        return "not yet born"; 
 +    }
     tmpCurrentDate.setHours(12);     tmpCurrentDate.setHours(12);
     var ageDays = 0;     var ageDays = 0;
-    while (tmpCurrentDate.getDate() != getNormalizedDate(tmpCurrentDate, tmpBirthDate)) { +    while (tmpCurrentDate.getDate() != getNormalizedDate(tmpCurrentDate, tmpBirthDate)) 
-      ageDays++; +    
-      tmpCurrentDate.setDate(tmpCurrentDate.getDate() - 1);+        ageDays++; 
 +        tmpCurrentDate.setDate(tmpCurrentDate.getDate() - 1);
     }     }
     tmpCurrentDate.setDate(1);     tmpCurrentDate.setDate(1);
     tmpBirthDate.setDate(1);     tmpBirthDate.setDate(1);
     var ageMonths = 0;     var ageMonths = 0;
-    while (tmpCurrentDate.getMonth() != tmpBirthDate.getMonth()) { +    while (tmpCurrentDate.getMonth() != tmpBirthDate.getMonth()) 
-      ageMonths++; +    
-      tmpCurrentDate.setMonth(tmpCurrentDate.getMonth() - 1);+        ageMonths++; 
 +        tmpCurrentDate.setMonth(tmpCurrentDate.getMonth() - 1);
     }     }
     var ageYears=0;     var ageYears=0;
-    while (tmpCurrentDate.getFullYear() != tmpBirthDate.getFullYear()) { +    while (tmpCurrentDate.getFullYear() != tmpBirthDate.getFullYear()) 
-      ageYears++; +    
-      tmpCurrentDate.setFullYear(tmpCurrentDate.getFullYear() - 1);+        ageYears++; 
 +        tmpCurrentDate.setFullYear(tmpCurrentDate.getFullYear() - 1);
     }     }
     return ageYears + ' year' + (ageYears == 1 ? '' : 's') + ', ' + ageMonths + ' month' + (ageMonths == 1 ? '' : 's') + ' and ' + ageDays + ' day' + (ageDays == 1 ? '' : 's');     return ageYears + ' year' + (ageYears == 1 ? '' : 's') + ', ' + ageMonths + ' month' + (ageMonths == 1 ? '' : 's') + ' and ' + ageDays + ' day' + (ageDays == 1 ? '' : 's');
   };   };
  
-  if (typeof(currentDate) == "undefined" || currentDate == "" || isNaN(currentDate)) { +    if (typeof(currentDate) == "undefined" || currentDate == "" || isNaN(currentDate)) 
-    currentDate = new Date(); +    
-  +        currentDate = new Date(); 
-  else +    
-  +    else 
-    currentDate = new Date(currentDate.substring(0,4), currentDate.substring(4,6) - 1, currentDate.substring(6, 8)); +    
-  +        currentDate = new Date(currentDate.substring(0,4), currentDate.substring(4,6) - 1,  currentDate.substring(6, 8)); 
-  if (typeof(birthDate) == "undefined" || birthDate == "" || isNaN(birthDate)) { +    
-    birthDate = new Date(); +    if (typeof(birthDate) == "undefined" || birthDate == "" || isNaN(birthDate)) 
-  +    
-  else +        birthDate = new Date(); 
-  {  +    
-    birthDate = new Date(birthDate.substring(0,4), birthDate.substring(4,6) - 1, birthDate.substring(6, 8)); +    else 
-  +    {  
-  return getAgeString(birthDate, currentDate);+        birthDate = new Date(birthDate.substring(0,4), birthDate.substring(4,6) - 1, birthDate.substring(6, 8)); 
 +    
 +    return getAgeString(birthDate, currentDate);
 }; };
 })(); })();
 </code>  </code> 
software/tiddlywiki.1397329889.txt.gz · Last modified: 2014/04/12 19:11 by superwizard