<commit_before>/* 
 * Original script by <NAME> (http://www.onlineaspect.com)
 * Continued and maintained by <NAME> at https://bitbucket.org/pellepim/jstimezonedetect
 *
 * Provided under the Do Whatever You Want With This Code License.
 */

/**
 * Namespace to hold all the code for timezone detection.
 */
var jstz = (function () {
    'use strict';
    var HEMISPHERE_SOUTH = 'SOUTH',
        HEMISPHERE_NORTH = 'NORTH',
        HEMISPHERE_UNKNOWN = 'N/A',
        
        /** 
         * Gets the offset in minutes from UTC for a certain date.
         * @param {Date} date
         * @returns {Number}
         */
        get_date_offset = function (date) {
            var offset = -date.getTimezoneOffset();
            return (offset !== null ? offset : 0);
        },
        
        get_january_offset = function () {
            return get_date_offset(new Date(2010, 0, 1, 0, 0, 0, 0));
        },
    
        get_june_offset = function () {
            return get_date_offset(new Date(2010, 5, 1, 0, 0, 0, 0));
        },
        
        /**
         * Private method.
         * Checks whether a given date is in daylight savings time.
         * If the date supplied is after june, we assume that we're checking
         * for southern hemisphere DST.
         * @param {Date} date
         * @returns {Boolean}
         */
        date_is_dst = function (date) {
            var base_offset = ((date.getMonth() > 5 ? get_june_offset() 
                                                : get_january_offset())),
                date_offset = get_date_offset(date); 
            
            return (base_offset - date_offset) !== 0;
        },
    
        /**
         * This function does some basic calculations to create information about 
         * the user's timezone.
         * 
         * Returns a primitive object on the format
         * {'utc_offset' : -9, 'dst': 1, hemisphere' : 'north'}
         * where dst is 1 if the region uses daylight savings.
         * 
         * @returns {Object}  
         */
        get_timezone_info = function () {
            var january_offset = get_january_offset(), 
                june_offset = get_june_offset(), 
                diff = get_january_offset() - get_june_offset(),
                TzInfo = function (o, d, h) {
                    this.utc_offset = o;
                    this.dst = d;
                    this.hemisphere = h;
                };
        
            if (diff < 0) {
                return new TzInfo(january_offset, 1, HEMISPHERE_NORTH);
            } else if (diff > 0) {
                return new TzInfo(june_offset, 1, HEMISPHERE_SOUTH);
            }
    
            return new TzInfo(january_offset, 0, HEMISPHERE_UNKNOWN);
        },
    
        /**
         * Uses get_timezone_info() to formulate a key to use in the olson.timezones dictionary.
         * 
         * Returns a primitive object on the format:
         * {'timezone': TimeZone, 'key' : 'the key used to find the TimeZone object'}
         * 
         * @returns Object 
         */
        determine_timezone = function () {
            var timezone_key_info = get_timezone_info(),
                hemisphere_suffix = timezone_key_info.hemisphere === HEMISPHERE_SOUTH ? ',s' : '',
                tz_key = timezone_key_info.utc_offset + ',' + timezone_key_info.dst + hemisphere_suffix;
                
            return new jstz.TimeZone(jstz.olson.timezones[tz_key]);
        };
    
    return {
        determine_timezone : determine_timezone,
        date_is_dst : date_is_dst
    };
}());

/**
 * A simple object containing information of utc_offset, which olson timezone key to use, 
 * and if the timezone cares about daylight savings or not.
 * 
 * @constructor
 * @param {string} offset - for example '-11:00'<commit_msg>Simplified get_timezone_info() function into lookup_key() function.<commit_after>/* 
 * Original script by <NAME> (http://www.onlineaspect.com)
 * Continued and maintained by <NAME> at https://bitbucket.org/pellepim/jstimezonedetect
 *
 * Provided under the Do Whatever You Want With This Code License.
 */

/**
 * Namespace to hold all the code for timezone detection.
 */
var jstz = (function () {
    'use strict';
    var HEMISPHERE_SOUTH = 'SOUTH',
        
        /** 
         * Gets the offset in minutes from UTC for a certain date.
         * @param {Date} date
         * @returns {Number}
         */
        get_date_offset = function (date) {
            var offset = -date.getTimezoneOffset();
            return (offset !== null ? offset : 0);
        },
        
        get_january_offset = function () {
            return get_date_offset(new Date(2010, 0, 1, 0, 0, 0, 0));
        },
    
        get_june_offset = function () {
            return get_date_offset(new Date(2010, 5, 1, 0, 0, 0, 0));
        },
        
        /**
         * Private method.
         * Checks whether a given date is in daylight savings time.
         * If the date supplied is after june, we assume that we're checking
         * for southern hemisphere DST.
         * @param {Date} date
         * @returns {Boolean}
         */
        date_is_dst = function (date) {
            var base_offset = ((date.getMonth() > 5 ? get_june_offset() 
                                                : get_january_offset())),
                date_offset = get_date_offset(date); 
            
            return (base_offset - date_offset) !== 0;
        },
    
        /**
         * This function does some basic calculations to create information about 
         * the user's timezone.
         * 
         * Returns a key that can be used to do lookups in jstz.olson.timezones.
         * 
         * @returns {String}  
         */
        
        lookup_key = function () {
            var january_offset = get_january_offset(), 
                june_offset = get_june_offset(), 
                diff = get_january_offset() - get_june_offset();
                
            if (diff < 0) {
                return january_offset + ",1";
            } else if (diff > 0) {
                return june_offset + ",1," + HEMISPHERE_SOUTH;
            }
            
            return january_offset + ",0";
        },
    
        /**
         * Uses get_timezone_info() to formulate a key to use in the olson.timezones dictionary.
         * 
         * Returns a primitive object on the format:
         * {'timezone': TimeZone, 'key' : 'the key used to find the TimeZone object'}
         * 
         * @returns Object 
         */
        determine_timezone = function () {
            var key = lookup_key();
            return new jstz.TimeZone(jstz.olson.timezones[key]);
        };
    
    return {
        determine_timezone : determine_timezone,
        date_is_dst : date_is_dst
    };
}());

/**
 * A simple object containing information of utc_offset, which olson timezone key to use, 
 * and if the timezone cares about daylight savings or not.
 * 
 * @constructor
 * @param {string} offset - for example '-11:00'
{'fraction_non_alphanumeric': 0.099261573416643, 'fraction_numerical': 0.009514342516330588, 'mean_word_length': 1.6657834973504921, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '187271', 'n_tokens_mistral': 2115, 'n_tokens_neox': 1989, 'n_words': 577}