#!/usr/bin/env node

var suncalc = require('suncalc'),
    request = require('request'),
    moment = require('moment'),
    chalk = require('chalk'),
    geolocation_url = 'https://maps.googleapis.com/maps/api/browserlocation/json?browser=chromium&sensor=true';

request(geolocation_url, function (err, res, body) {
    var geolocation_data = JSON.parse(body);
    var suncalc_data = suncalc.getTimes(new Date(), geolocation_data.location.lat, geolocation_data.location.lng);
    console.log(chalk.yellow('Dawn: ') + moment(suncalc_data.dawn).calendar());
    console.log(chalk.yellow('Sunrise: ') + moment(suncalc_data.sunrise).calendar());
    console.log(chalk.yellow('Sunset: ') + moment(suncalc_data.sunset).calendar());
    console.log(chalk.yellow('Dusk: ') + moment(suncalc_data.dusk).calendar());
});

@@ -318,327 +318,524 @@
     
-var geolocation_data = JSON.parse(body);%0A    var suncalc_data = suncalc.getTimes(new Date(), geolocation_data.location.lat, geolocation_data.location.lng);%0A    console.log(chalk.yellow('Dawn: ') + moment(suncalc_data.dawn).calendar());%0A    console.log(chalk.yellow('Sunrise: ') + moment(suncalc_data.sunrise).calendar()
+if (err) %7B%0A        console.log(chalk.red('Geolocation request failed.%5Cn' + err));%0A        return;%0A    %7D%0A    var geolocation_data = JSON.parse(body);%0A    display(geolocation_data.location);%0A%7D);%0A%0Afunction display (coords) %7B%0A    var sun_times = suncalc.getTimes(new Date(), coords.lat, coords.lng);%0A    var moon_illumination = suncalc.getMoonIllumination(new Date());%0A    output('Dawn', sun_times.dawn);%0A    output('Sunrise', sun_times.sunrise);%0A    output('Sunset', sun_times.sunset);%0A    output('Dusk', sun_times.dusk
 );%0A 
@@ -859,69 +859,125 @@
 alk.
-yellow('Sun
+blue('Moon Pha
 se
-t
 : ') + 
-moment(suncalc_data.sunset).calendar());
+phase(moon_illumination.fraction, moon_illumination.angle));%0A%7D%0A%0Afunction output (name, date) %7B
 %0A   
@@ -1002,21 +1002,24 @@
 .yellow(
-'Dusk
+name + '
 : ') + m
@@ -1028,40 +1028,169 @@
 ent(
-suncalc_data.dusk).calendar());%0A%7D);
+date).calendar());%0A%7D%0A%0Afunction phase (fraction, angle) %7B%0A    if (angle %3E 0) %7B%0A        return 'Waning';%0A    %7D else if (angle %3C 0) %7B%0A        return 'Waxing ';%0A    %7D%0A%7D
 %0A

add waning/waxing data