Permalink
Browse files

Add output of firstFromTime() and lastFromTime() to README example

  • Loading branch information...
1 parent 7840bdc commit 0d48b2fc1559259ea8a88825a89ad224828de65b @ctavan ctavan committed Nov 13, 2011
Showing with 15 additions and 3 deletions.
  1. +15 −3 README.md
View
@@ -5,21 +5,33 @@ A js library to generate and parse UUID's, TimeUUID's and generate empty TimeUUI
```javascript
var UUID = require('uuid-js');
-var uuid4 = UUID.create(); // Generate a V4 UUID
+// Generate a V4 UUID
+var uuid4 = UUID.create();
console.log(uuid4.toString());
// Prints: 896b677f-fb14-11e0-b14d-d11ca798dbac
-var uuid1 = UUID.create(1); // Generate a V1 TimeUUID
+
+// Generate a V1 TimeUUID
+var uuid1 = UUID.create(1);
console.log(uuid1.toString());
+
+// First and last possible v1 TimeUUID for a given timestamp:
+var date = new Date().getTime();
+var uuidFirst = UUID.fromTime(date, false);
+var uuidLast = UUID.fromTime(date, true);
+console.log(uuidFirst.toString(), uuidLast.toString());
+// Prints: aa0f9af0-0e1f-11e1-0000-000000000000 aa0f9af0-0e1f-11e1-c0ff-ffffffffffff
+
+
+// Use these TimeUUID's to perform range queries in cassandra:
var today = new Date().getTime();
var last30days = (new Date().setDate( today.getDate() - 30 )).getTime();
var rangeStart = UUID.firstFromTime(last30days);
var rangeEnd = UUID.lastFromTime(today);
-// Example using cassandra
var query = ...("select first 50 reversed ?..? from user_twits where key=?", [ rangeStart, rangeEnd, "patricknegri" ]);
```

0 comments on commit 0d48b2f

Please sign in to comment.