<commit_before>'use strict';

import { h, Component } from 'preact';
import { bind } from 'decko';

const availablePeriods = [
  {
    id: 'day',
    label: 'Today'
  },
  {
    id: 'week',
    label: 'This week'
  },
  {
    id: 'month',
    label: 'This month'
  },
  {
    id: 'year',
    label: 'This year'
  }
]

class DatePicker extends Component {
  constructor(props) {
    super(props)

    this.state = {
      period: props.value,
      before: 0,
      after: 0,
    }

    this.setTimeRange(this.state.period)
  }

  @bind
  setTimeRange(period) {
    let beforeDate = new Date();
    beforeDate.setHours(24);
    beforeDate.setMinutes(0);

    let afterDate = new Date();
    afterDate.setHours(0);
    afterDate.setMinutes(0);
    switch(period) {
      case "week":
        afterDate.setDate(afterDate.getDate() - (afterDate.getDay() + 6) % 7);
      break;
      case "month":
        afterDate.setDate(1);
      break;
      case "year":
        afterDate.setDate(1);
        afterDate.setMonth(0);
      break;
    }

    let before, after;
    before = Math.round((+beforeDate ) / 1000);
    after = Math.round((+afterDate) / 1000);
    this.setState({
      period: period,
      before: before, 
      after: after,
    });
    this.props.onChange(this.state);
  }

  @bind
  setPeriod(e) {
    e.preventDefault();

    let newPeriod = e.target.dataset.value;
    if( newPeriod === this.state.period) {
      return;
    }

    this.setTimeRange(newPeriod);
  }
<commit_msg>add local timezone offset to utc timestamps we send to server. #31<commit_after>'use strict';

import { h, Component } from 'preact';
import { bind } from 'decko';

const availablePeriods = [
  {
    id: 'day',
    label: 'Today'
  },
  {
    id: 'week',
    label: 'This week'
  },
  {
    id: 'month',
    label: 'This month'
  },
  {
    id: 'year',
    label: 'This year'
  }
]

class DatePicker extends Component {
  constructor(props) {
    super(props)

    this.state = {
      period: props.value,
      before: 0,
      after: 0,
    }

    this.setTimeRange(this.state.period)
  }

  @bind
  setTimeRange(period) {
    const timezoneOffset = (new Date()).getTimezoneOffset() * 60;
    let beforeDate = new Date();
    beforeDate.setHours(24);
    beforeDate.setMinutes(0);

    let afterDate = new Date();
    afterDate.setHours(0);
    afterDate.setMinutes(0);
    switch(period) {
      case "week":
        afterDate.setDate(afterDate.getDate() - (afterDate.getDay() + 6) % 7);
      break;
      case "month":
        afterDate.setDate(1);
      break;
      case "year":
        afterDate.setDate(1);
        afterDate.setMonth(0);
      break;
    }

    let before, after;

    before = Math.round(((+beforeDate) / 1000) + timezoneOffset);
    after = Math.round(((+afterDate) / 1000) + timezoneOffset);
    this.setState({
      period: period,
      before: before, 
      after: after,
    });
    this.props.onChange(this.state);
  }

  @bind
  setPeriod(e) {
    e.preventDefault();

    let newPeriod = e.target.dataset.value;
    if( newPeriod === this.state.period) {
      return;
    }

    this.setTimeRange(newPeriod);
  }

{'fraction_non_alphanumeric': 0.1454429977770721, 'fraction_numerical': 0.013972689742775483, 'mean_word_length': 2.3475026567481403, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '4313011', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1082, 'n_words': 228}