<commit_before>import { h, Component } from 'preact/preact';
import SVGIcon 			from 'com/svg-icon/icon';

export default class SidebarCalendar extends Component {
	constructor( props ) {
		super(props);
		
		this.rows = 3;
		this.columns = 7;

		this.genCalendar( new Date() );
	}

	genCalendar( today ) {
		// TODO: Adjust noted days based on timezone
		// TODO: Adjust selected day/week when time itself rolls over

		let thisDay = today.getDate();
		let thisMonth = today.getMonth();
		let thisYear = today.getFullYear();
		
		/* Months and Weeks start at 0. Years and Days start at 1. Using 0th day is like -1 */
		let monthEndsOn = new Date(today.getFullYear(), today.getMonth(), 0).getDate();
		let nextDay = today.getDate() - today.getDay();
		
		if ( nextDay < 1 ) {
			let lastMonth = new Date(today.getFullYear(),today.getMonth(),0);
			monthEndsOn = lastMonth.getDate();
			//console.log( lastMonth.getFullYear(), lastMonth.getMonth(), lastMonth.getDate(), lastMonth.getDay() );
			nextDay = lastMonth.getDate() - lastMonth.getDay();
		}
		
		this.data = Array(...Array(this.rows)).map(() => Array.from( Array(this.columns),function(){
			let ret = {
				'year': thisYear,
				'month': thisMonth,
				'day': nextDay
			};
			
			if ( nextDay === thisDay ) {
				ret['selected'] = true;
			}
			
			nextDay++;
			if ( nextDay > monthEndsOn ) {
				nextDay -= monthEndsOn;
				thisMonth++;
				if ( thisMonth > 12 ) {
					thisYear++;
					thisMonth = 1;
				}
			}
			
			return ret;
		}));
	}

	genRow( row ) {
		return row.map(col => {
			let props = {};
			if ( col.selected ) {
				props.class = "selected";
			}
			props.onclick = (e) => {
				console.log('cal: ',col); 
				window.location.hash = "#cal/"+col.year+"/"+col.month+"/"+col.day;
			};
			// In case Intl extensions are not available
			props.title = col.month+"-"+col.day+"-"+col.year;
			if ( window.Intl ) {
				// http://stackoverflow.com/a/18648314/5678759
				let objDate = new Date(col.year, col.month-1, col.day);
				props.title = objDate.toLocaleString("en-us", {month:"long", day:"numeric", year:"numeric"});
			}
			
			// Hack
			var ShowIcon = null;
			if ( col.year == 2016 && col.month == 11 && (col.day >= 9 && col.day <= 12) ) {
				ShowIcon = <SVGIcon class="-icon">trophy</SVGIcon>;
			}

			return (
				<div {...props}>
					{ShowIcon}
					<div class="-text">{col.day}</div>
				</div>
			); 
		});
	}
	
	genWeek( row ) {
		return (
			<div class="-week">
			{this.genRow(row)}
			</div><commit_msg>Fix for the calender hover 'off by 1 month'<commit_after>import { h, Component } from 'preact/preact';
import SVGIcon 			from 'com/svg-icon/icon';

export default class SidebarCalendar extends Component {
	constructor( props ) {
		super(props);
		
		this.rows = 3;
		this.columns = 7;

		this.genCalendar( new Date() );
	}

	genCalendar( today ) {
		// TODO: Adjust noted days based on timezone
		// TODO: Adjust selected day/week when time itself rolls over

		let thisDay = today.getDate();
		let thisMonth = today.getMonth();
		let thisYear = today.getFullYear();
		
		/* Months and Weeks start at 0. Years and Days start at 1. Using 0th day is like -1 */
		let monthEndsOn = new Date(today.getFullYear(), today.getMonth(), 0).getDate();
		let nextDay = today.getDate() - today.getDay();
		
		if ( nextDay < 1 ) {
			let lastMonth = new Date(today.getFullYear(), today.getMonth(),0);
			monthEndsOn = lastMonth.getDate();
			//console.log( lastMonth.getFullYear(), lastMonth.getMonth(), lastMonth.getDate(), lastMonth.getDay() );
			nextDay = lastMonth.getDate() - lastMonth.getDay();
		}
		
		this.data = Array(...Array(this.rows)).map(() => Array.from( Array(this.columns),function(){
			let ret = {
				'year': thisYear,
				'month': thisMonth,
				'day': nextDay
			};
			
			if ( nextDay === thisDay ) {
				ret['selected'] = true;
			}
			
			nextDay++;
			if ( nextDay > monthEndsOn ) {
				nextDay -= monthEndsOn;
				thisMonth++;
				if ( thisMonth > 12 ) {
					thisYear++;
					thisMonth = 1;
				}
			}
			
			return ret;
		}));
	}

	genRow( row ) {
		return row.map(col => {
			let props = {};
			if ( col.selected ) {
				props.class = "selected";
			}
			props.onclick = (e) => {
				console.log('cal: ',col); 
				window.location.hash = "#cal/"+col.year+"/"+col.month+"/"+col.day;
			};
			// In case Intl extensions are not available
			props.title = col.month+"-"+col.day+"-"+col.year;
			if ( window.Intl ) {
				// http://stackoverflow.com/a/18648314/5678759
				let objDate = new Date(col.year, col.month, col.day);
				props.title = objDate.toLocaleString("en-us", {month:"long", day:"numeric", year:"numeric"});
			}
			
			// Hack
			var ShowIcon = null;
			if ( col.year == 2016 && col.month == 11 && (col.day >= 9 && col.day <= 12) ) {
				ShowIcon = <SVGIcon class="-icon">trophy</SVGIcon>;
			}

			return (
				<div {...props}>
					{ShowIcon}
					<div class="-text">{col.day}</div>
				</div>
			); 
		});
	}
	
	genWeek( row ) {
		return (
			<div class="-week">
			{this.genRow(row)}
			</div>
{'fraction_non_alphanumeric': 0.17565148199721503, 'fraction_numerical': 0.01472050925004973, 'mean_word_length': 2.749440715883669, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3294951', 'n_tokens_mistral': 2163, 'n_tokens_neox': 1736, 'n_words': 404}