software:tiddlywiki
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
software:tiddlywiki [2014/04/12 19:11] – created superwizard | software: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:// | ||
< | < | ||
Line 10: | Line 12: | ||
exports.params = [ { name: " | exports.params = [ { name: " | ||
- | exports.run = function(birthDate, | + | exports.run = function(birthDate, |
- | var getNormalizedDate = function (date, referenceDate) { | + | { |
+ | var getNormalizedDate = function (date, referenceDate) { | ||
var numberOfDaysInMonth = (new Date(date.getFullYear(), | var numberOfDaysInMonth = (new Date(date.getFullYear(), | ||
- | 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(), | var tmpCurrentDate = new Date(currentDate.getFullYear(), | ||
- | if (tmpCurrentDate < tmpBirthDate) return "not yet born"; | + | if (tmpCurrentDate < tmpBirthDate) |
+ | ( | ||
+ | | ||
+ | } | ||
tmpCurrentDate.setHours(12); | tmpCurrentDate.setHours(12); | ||
var ageDays = 0; | var ageDays = 0; | ||
- | while (tmpCurrentDate.getDate() != getNormalizedDate(tmpCurrentDate, | + | while (tmpCurrentDate.getDate() != getNormalizedDate(tmpCurrentDate, |
- | 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 ? '' | return ageYears + ' year' + (ageYears == 1 ? '' | ||
}; | }; | ||
- | | + | |
- | currentDate = new Date(); | + | |
- | } | + | |
- | else | + | } |
- | { | + | else |
- | currentDate = new Date(currentDate.substring(0, | + | { |
- | } | + | currentDate = new Date(currentDate.substring(0, |
- | if (typeof(birthDate) == " | + | } |
- | birthDate = new Date(); | + | if (typeof(birthDate) == " |
- | } | + | |
- | else | + | |
- | { | + | } |
- | birthDate = new Date(birthDate.substring(0, | + | else |
- | } | + | { |
- | return getAgeString(birthDate, | + | birthDate = new Date(birthDate.substring(0, |
+ | } | ||
+ | return getAgeString(birthDate, | ||
}; | }; | ||
})(); | })(); | ||
</ | </ |
software/tiddlywiki.1397329889.txt.gz · Last modified: 2014/04/12 19:11 by superwizard