Skip to content

Instantly share code, notes, and snippets.

@ptquang86
ptquang86 / ti.log.js
Created March 27, 2012 06:34
Titanium - Log info
/*
log info
usage: log(1,'hehe', { name: 'test' })
*/
function log() {
var arr = [];
for(var i = 0, ii = arguments.length; i < ii; i++){
switch(typeof(arguments[i])) {
case 'array': case 'object':
@ptquang86
ptquang86 / ti.button.js
Created March 27, 2012 06:38
Titanium - Gradient Button
Ti.UI.createButton({
width: 100,
height: 30,
title: 'Edit Profile',
font: { fontSize: 14 },
borderRadius: 5,
borderColor: 'blue',
style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN,
backgroundGradient:{
type:'linear',
@ptquang86
ptquang86 / ti.layout.js
Created March 27, 2012 06:42
Titanium - Layout function
/*
Layout constructor
usage:
var oLayout = {
type: 'View',
style: { width: 100, height: 200 },
event: {
type: 'click',
callback: function(){}
@ptquang86
ptquang86 / js.numberFormat.js
Created March 27, 2012 06:45
Javascript - Format number
exports.digits = function(number){
if (!isNaN(number)) {
number += '';
}
if (number == '') {
return 0;
}
number = exports.replaceAll(number, ',', '');
@ptquang86
ptquang86 / titanium.module.js
Created May 28, 2012 07:34
CommonJS modules
function Car() {
this.init.apply(this, arguments);
}
Car.prototype.init = function (make, model) {
this.make = make;
this.model = model;
};
Car.prototype.make = null;
@ptquang86
ptquang86 / format.date.js
Created June 8, 2012 06:11
JavaScript Date Format
//http://blog.stevenlevithan.com/archives/date-time-format
//http://stevenlevithan.com/assets/misc/date.format.js
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
@ptquang86
ptquang86 / ti.geo.js
Last active April 8, 2016 18:40
Titanium - Geolocation
exports.init = function() {
Ti.Geolocation.purpose = 'Mileage Calculate';
checkGeoPermission();
Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;
//
// SET ACCURACY - THE FOLLOWING VALUES ARE SUPPORTED
//
@ptquang86
ptquang86 / js-cache-function-result.js
Created November 18, 2012 09:01
Javascript - Cache function result
// http://www.sitekickr.com/blog/?p=946&preview=true
function Cache() {
// create the cache object as a singleton (only one instance allowed)
if(typeof Cache.instance === 'undefined') {
Cache.instance = this;
}
var data = [ ]

Working with Dates, Times, and Timezones

Top 10 recommendations for developers

Update: tzTime (documentation) is now available seperately from Lumenize. The examples below still work because tzTime is a dependency of Lumenize and included in that package (as well as Rally's App SDK v2.0p6 or greater). However, Lumenize includes a lot more functionality around time-series and temporal model aggregations, OLAP Cube, etc. If you just want the Time object, just grab tzTime.

What's the correct query clause to get all the transactions from March? The naive answer is "2012-03-01" &lt;= eventTimestamp &lt;= "2012-03-31" but what if the person worked in the eastern US and wanted timezone taken into account? Then the correct answer is "2012-03-01T05" &lt;= eventTimestamp &lt; "2012-04-01T04". Notice how the timeshift for the begging of March is different from the end. Getting this right is mind bendingly diff

// vendor
var express = require('express');
var app = express();
// depending on the placement, we can either catch or override routes
app.use(app.router);
// every route in the routes/user.js file will be served under /user
app.use('/user', require('./routes/user').middleware);