Permalink
Browse files

* HACKING:

	  Add notes on date stuff.
	* couchdb/_attachments/jquery.gtd.js:
	  Comment that we need date.js loaded.
	  Remove unused function.
	  Comment prettyDate.
	* couchdb/vendor/couchapp/date.js:
	  Add Date.setRFC3339()
	* couchdb/vendor/couchapp/_attachments/date.js:
	  Create a symlink so that we can also serve date.js to browser.
	* couchdb/views/recent-things/map.js:
	  Only emit docs with a start date.
	* couchdb/templates/index/row.html:
	  It's title, not description.
	* couchdb/templates/thing.html:
	* couchdb/templates/index/tail.html:
	  Make sure we include date.js before jquery.gtd.js
  • Loading branch information...
1 parent 6fae0bc commit 0ab266e029890ec2f0bda883c53c7d4eb37938f5 Thomas Vander Stichele committed Nov 21, 2009
View
@@ -1,5 +1,25 @@
2009-11-21 Thomas Vander Stichele <thomas at apestaart dot org>
+ * HACKING:
+ Add notes on date stuff.
+ * couchdb/_attachments/jquery.gtd.js:
+ Comment that we need date.js loaded.
+ Remove unused function.
+ Comment prettyDate.
+ * couchdb/vendor/couchapp/date.js:
+ Add Date.setRFC3339()
+ * couchdb/vendor/couchapp/_attachments/date.js:
+ Create a symlink so that we can also serve date.js to browser.
+ * couchdb/views/recent-things/map.js:
+ Only emit docs with a start date.
+ * couchdb/templates/index/row.html:
+ It's title, not description.
+ * couchdb/templates/thing.html:
+ * couchdb/templates/index/tail.html:
+ Make sure we include date.js before jquery.gtd.js
+
+2009-11-21 Thomas Vander Stichele <thomas at apestaart dot org>
+
* python/things/command/replicate.py:
Handle replication setup failures.
View
10 HACKING
@@ -60,3 +60,13 @@ couchdb part:
couchapp push couchdb gtd http://thomas:pass@localhost:5984/gtd/
+QUESTIONS
+
+ - where to store .js code that you want to use both server-side and
+ client-side ? For example, date.js and its setRFC3339 function.
+ e.g. http://localhost:5984/gtd/_design/gtd/jquery.gtd.js
+ is stored at couchdb/_attachments/jquery.gtd.js
+ e.g. http://localhost:5984/gtd/_design/gtd/vendor/couchapp/jquery.couchapp.js
+ is stored at couchdb/vendor/couchapp/_attachments/jquery.couchapp.js
+ For now, we created a symlink
+
@@ -18,21 +18,10 @@
// ...
// });
-(function($) {
+// this needs vendor/couchapp/date.js loaded first
- function f(n) { // Format integers to have at least two digits.
- return n < 10 ? '0' + n : n;
- }
+(function($) {
- Date.prototype.toJSON = function() {
- return this.getUTCFullYear() + '/' +
- f(this.getUTCMonth() + 1) + '/' +
- f(this.getUTCDate()) + ' ' +
- f(this.getUTCHours()) + ':' +
- f(this.getUTCMinutes()) + ':' +
- f(this.getUTCSeconds()) + ' +0000';
- };
-
function Design(db, name) {
this.view = function(view, opts) {
db.view(name+'/'+view, opts);
@@ -43,12 +32,11 @@
function init(app) {
$(function() {
- function prettyDate(time){
- var date = new Date(time),
- diff = (((new Date()).getTime() - date.getTime()) / 1000),
- day_diff = Math.floor(diff / 86400);
-
- // if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 ) return;
+ // This function takes strings of the form 2009-11-21T22:49:58Z
+ function prettyDate(time) {
+ var date = new Date().setRFC3339(time);
+ var diff = ((new Date()).getTime() - date.getTime()) / 1000;
+ var day_diff = Math.floor(diff / 86400);
return day_diff < -730 && Math.ceil(-day_diff / -365) + " years from now" ||
day_diff < -45 && Math.ceil(-day_diff / 31) + " months from now" ||
@@ -1,5 +1,5 @@
<li>
- <h3><a href="{{link}}">{{description}}</a></h3>
+ <h3><a href="{{link}}">{{title}}</a></h3>
<span>started <span class="date">{{start}}</span></span>
{{#notempty}}
<span>due <span class="date">{{due}}</span></span>
@@ -4,6 +4,7 @@
<script src="/_utils/script/json2.js"></script>
<script src="/_utils/script/jquery.js"></script>
<script src="/_utils/script/jquery.couch.js"></script>
+<script src="<%= assets %>/vendor/couchapp/date.js"></script>
<script src="<%= assets %>/jquery.gtd.js"></script>
<script type="text/javascript" charset="utf-8">
$.GTDApp(function(app) {
@@ -27,6 +27,7 @@
<script src="/_utils/script/json2.js"></script>
<script src="/_utils/script/jquery.js?1.2.6"></script>
<script src="/_utils/script/jquery.couch.js?0.8.0"></script>
+ <script src="<%= assets %>/vendor/couchapp/date.js"></script>
<script src="<%= assets %>/jquery.gtd.js"></script>
<script src="<%= assets %>/thing.js"></script>
<script type="text/javascript" charset="utf-8">
@@ -20,4 +20,38 @@ Date.prototype.toJSON = function() {
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + ' +0000';
-};
+};
+
+// Lifted from
+// http://bitbucket.org/benoitc/benoitcim/src/tip/vendor/inditeweb/date.js
+// adapted to make the trailing Z optional, and remove fractional seconds
+// Also see FIXME
+Date.prototype.setRFC3339 = function(dString){
+ //var regexp = /(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)(\.\d+)?(Z|([+-])(\d\d)(:)?(\d\d))?/;
+ var regexp = /(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)?/;
+
+ if (dString.toString().match(new RegExp(regexp))) {
+ var d = dString.match(new RegExp(regexp));
+ var offset = 0;
+
+ this.setUTCDate(1);
+ this.setUTCFullYear(parseInt(d[1],10));
+ this.setUTCMonth(parseInt(d[3],10) - 1);
+ this.setUTCDate(parseInt(d[5],10));
+ this.setUTCHours(parseInt(d[7],10));
+ this.setUTCMinutes(parseInt(d[9],10));
+ this.setUTCSeconds(parseInt(d[11],10));
+ //if (d[12])
+ // this.setUTCMilliseconds(parseFloat(d[12]) * 1000);
+ //else
+ // this.setUTCMilliseconds(0);
+ //if (d[13] != 'Z') {
+ // offset = (d[15] * 60) + parseInt(d[17],10);
+ // offset *= ((d[14] == '-') ? -1 : 1);
+ // this.setTime(this.getTime() - offset * 60 * 1000);
+ //}
+ } else {
+ this.setTime(Date.parse(dString));
+ }
+ return this;
+};
@@ -1,7 +1,7 @@
function(doc) {
- if (doc.type == "thing") {
+ if (doc.type == "thing" && doc.start !== null) {
emit(doc.start, {
- description : doc.description,
+ title : doc.title,
start : doc.start,
due : doc.due || null
});

0 comments on commit 0ab266e

Please sign in to comment.