<commit_before>// sg_time.cxx -- data structures and routines for managing time related stuff.
//
// Written by <NAME>, started August 1997.
//
// Copyright (C) 1997  <NAME>  - <EMAIL>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA  02111-1307, USA.
//
// $Id$


#ifdef HAVE_CONFIG_H
#  include <simgear_config.h>
#endif

#include <simgear/compiler.h>

#include <errno.h>		// for errno

#ifdef SG_HAVE_STD_INCLUDES
#  include <cstdio>
#  include <cstdlib>
#  include <ctime>
#else
#  include <math.h>
#  include <stdio.h>
#  include <stdlib.h>
#endif

#ifdef HAVE_SYS_TIME_H
#  include <sys/time.h>  // for get/setitimer, gettimeofday, struct timeval
#endif
#ifdef HAVE_SYS_TIMEB_H
#  include <sys/timeb.h> // for ftime() and struct timeb
#endif
#ifdef HAVE_UNISTD_H
#  include <unistd.h>    // for gettimeofday()
#endif

#include <math.h>        // for NAN

#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx>

#include "sg_time.hxx"
#include "timezone.h"
#include "lowleveltime.h"


#define DEGHR(x)        ((x)/15.)
#define RADHR(x)        DEGHR(x*SGD_RADIANS_TO_DEGREES)


static const double MJD0    = 2415020.0;
static const double J2000   = 2451545.0 - MJD0;
static const double SIDRATE = 0.9972695677;


void SGTime::init( double lon, double lat,
                   const string& root, time_t init_time )
{
    SG_LOG( SG_EVENT, SG_INFO, "Initializing Time" );

    gst_diff = -9999.0;

    if ( init_time ) {
	cur_time = init_time;
    } else {
	cur_time = time(NULL); 
    }

    cout << "Current greenwich mean time = " << asctime(gmtime(&cur_time))
         << endl;
    cout << "Current local time          = " 
         << asctime(localtime(&cur_time)) << endl;

    if ( root != (string)"" ) {
        SGPath zone( root );
        zone.append( "zone.tab" );
        SG_LOG( SG_EVENT, SG_INFO, "Reading timezone info from: "
                << zone.str() );
        tzContainer = new TimezoneContainer( zone.c_str() );

        GeoCoord location( SGD_RADIANS_TO_DEGREES * lat, SGD_RADIANS_TO_DEGREES * lon );
        GeoCoord* nearestTz = tzContainer->getNearest(location);

        SGPath name( root );
        name.append( nearestTz->getDescription() );
        zonename = strdup( name.c_str() );
        SG_LOG( SG_EVENT, SG_INFO, "Using zonename = " << zonename );
    } else {
        SG_LOG( SG_EVENT, SG_INFO, "*** NO TIME ZONE NAME ***" );
        tzContainer = NULL;
        zonename = NULL;
    }
}

SGTime::SGTime( double lon, double lat, const string& root, time_t init_time )
{
    init( lon, lat, root, init_time );
}


SGTime::SGTime( const string& root ) {
    init( 0.0, 0.0, root, 0 );
}
<commit_msg>string == "" -> string.empty() conversion.<commit_after>// sg_time.cxx -- data structures and routines for managing time related stuff.
//
// Written by <NAME>, started August 1997.
//
// Copyright (C) 1997  <NAME>  - <EMAIL>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA  02111-1307, USA.
//
// $Id$


#ifdef HAVE_CONFIG_H
#  include <simgear_config.h>
#endif

#include <simgear/compiler.h>

#include <errno.h>		// for errno

#ifdef SG_HAVE_STD_INCLUDES
#  include <cstdio>
#  include <cstdlib>
#  include <ctime>
#else
#  include <math.h>
#  include <stdio.h>
#  include <stdlib.h>
#endif

#ifdef HAVE_SYS_TIME_H
#  include <sys/time.h>  // for get/setitimer, gettimeofday, struct timeval
#endif
#ifdef HAVE_SYS_TIMEB_H
#  include <sys/timeb.h> // for ftime() and struct timeb
#endif
#ifdef HAVE_UNISTD_H
#  include <unistd.h>    // for gettimeofday()
#endif

#include <math.h>        // for NAN

#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx>

#include "sg_time.hxx"
#include "timezone.h"
#include "lowleveltime.h"


#define DEGHR(x)        ((x)/15.)
#define RADHR(x)        DEGHR(x*SGD_RADIANS_TO_DEGREES)


static const double MJD0    = 2415020.0;
static const double J2000   = 2451545.0 - MJD0;
static const double SIDRATE = 0.9972695677;


void SGTime::init( double lon, double lat,
                   const string& root, time_t init_time )
{
    SG_LOG( SG_EVENT, SG_INFO, "Initializing Time" );

    gst_diff = -9999.0;

    if ( init_time ) {
	cur_time = init_time;
    } else {
	cur_time = time(NULL); 
    }

    cout << "Current greenwich mean time = " << asctime(gmtime(&cur_time))
         << endl;
    cout << "Current local time          = " 
         << asctime(localtime(&cur_time)) << endl;

    if ( !root.empty()) {
        SGPath zone( root );
        zone.append( "zone.tab" );
        SG_LOG( SG_EVENT, SG_INFO, "Reading timezone info from: "
                << zone.str() );
        tzContainer = new TimezoneContainer( zone.c_str() );

        GeoCoord location( SGD_RADIANS_TO_DEGREES * lat, SGD_RADIANS_TO_DEGREES * lon );
        GeoCoord* nearestTz = tzContainer->getNearest(location);

        SGPath name( root );
        name.append( nearestTz->getDescription() );
        zonename = strdup( name.c_str() );
        SG_LOG( SG_EVENT, SG_INFO, "Using zonename = " << zonename );
    } else {
        SG_LOG( SG_EVENT, SG_INFO, "*** NO TIME ZONE NAME ***" );
        tzContainer = NULL;
        zonename = NULL;
    }
}

SGTime::SGTime( double lon, double lat, const string& root, time_t init_time )
{
    init( lon, lat, root, init_time );
}


SGTime::SGTime( const string& root ) {
    init( 0.0, 0.0, root, 0 );
}

{'fraction_non_alphanumeric': 0.123760177646188, 'fraction_numerical': 0.02013323464100666, 'mean_word_length': 2.9531889994148623, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 46, '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': '90734', 'n_tokens_mistral': 2489, 'n_tokens_neox': 2272, 'n_words': 697}