#include "stdafx.h"

#include <time.h>

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

namespace cx

{

 

 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

typedef void* pointer_t; // 4 bytes

 

//===========================================================================

typedef signed   int int_t ;

typedef unsigned int uint_t;

 

typedef signed             char int8_t  ; //                       -127 ~ +128

typedef signed   short     int  int16_t ; //                    -32,768 ~ +32,767

typedef signed   long      int  int32_t ; //             -2,147,483,648 ~ +2,147,483,647

typedef signed   long long int  int64_t ; // -9,223,372,036,854,775,808 ~ +9,223,372,036,854,775,807

typedef unsigned           char uint8_t ; // 0 ~ 255

typedef unsigned short     int  uint16_t; // 0 ~ 65,535

typedef unsigned long      int  uint32_t; // 0 ~ 4,294,967,295

typedef unsigned long long int  uint64_t; // 0 ~ 18,446,744,073,709,551,615

 

 

typedef bool bool_t;

 

typedef ::time_t time_t;

 

typedef unsigned char byte_t;

 

}

 

 

 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

/*

 

# Julian Period

15 (indiction cycle) × 19 (Metonic cycle) × 28 (Solar cycle) = 7980 years

첫 주기 : 4713 BC ~ AD 3268

 

# Julian Day

Julian Period의 일

천문학에서 사용

Julian Calendar 와는 다른 별도의 개념

 

# Julian Day Number(JDN)

정수 형태의 Julian

-4712/01/01 = 0(BC 4713)

-4712/01/02 = 1

-4712/01/03 = 2

JDN은 날짜 의미로만 사용

 

# Julian Date(JD)

실수 형태의 Julian

-4712/01/01 12:00:00 = 0.0

-4712/01/02 00:00:00 = 0.5

-4712/01/02 12:00:00 = 1.0

-4712/01/03 00:00:00 = 1.5

-4712/01/03 12:00:00 = 2.0

JD는 날짜+시간 의미 사용

 

# Julian Calendar

1582 10 04일 목요일 까지 사용

 

# Gregorian Calendar

1582 10 15일 금요일 부터 사용

 

# Calendar Date

1582 10 05 ~ 1582 10 14일은 존재 안함

 

# Unix Epoch Time

1970 01 01

윤초 없음

 

# 윤초

GMT 12 31 23:59:60 - 한국시간 01 01일 오전 08 59 60

GMT 06 30 23:59:60 - 한국시간 07 01일 오전 08 59 60

필요시 삽입됨

 

# Epoch Time

윤초 표시하지 않음

 

# 참고 URL

https://en.wikipedia.org/wiki/Julian_day

 

http://aa.usno.navy.mil/data/docs/JulianDate.php

https://www.tondering.dk/claus/cal/gregorian.php#country

http://jidolstar.tistory.com/482

 

*/

 

 

 

 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

void jdn_to_modified_jdn        (cx::int_t jdn, cx::int_t& modified_jdn);

void jdn_to_truncated_jd        (cx::int_t jdn, cx::int_t& truncated_jd);

void jdn_to_lilian_date         (cx::int_t jdn, cx::int_t& lilian_date);

void jdn_to_unix_time_day_count (cx::int_t jdn, cx::int_t& unix_time_day_count);

 

//===========================================================================

void gregorian_calendar_date_to_jdn (cx::int_t year, cx::int_t month, cx::int_t day, cx::int_t& jdn);

void julian_calendar_date_to_jdn    (cx::int_t year, cx::int_t month, cx::int_t day, cx::int_t& jdn);

void jdn_to_gregorian_calendar_date (cx::int_t jdn, cx::int_t& year, cx::int_t& month, cx::int_t& day);

void jdn_to_julian_calendar_date    (cx::int_t jdn, cx::int_t& year, cx::int_t& month, cx::int_t& day);

 

//===========================================================================

cx::int_t  calendar_date_from_1582_10_05_to_1582_10_14 (cx::int_t year, cx::int_t month, cx::int_t day);

 

cx::bool_t calendar_date_to_jdn (cx::int_t year, cx::int_t month, cx::int_t day, cx::int_t& jdn);

void       jdn_to_calendar_date (cx::int_t jdn, cx::int_t& year, cx::int_t& month, cx::int_t& day);

 

//===========================================================================

cx::int_t us_get_day_of_week  (cx::int_t jdn);

cx::int_t iso_get_day_of_week (cx::int_t jdn);

 

//===========================================================================

cx::bool_t gregorian_calendar_is_leap_year          (cx::int_t year);

cx::bool_t gregorian_calendar_get_last_day_of_month (cx::int_t year, cx::int_t month, cx::int_t& day);

cx::bool_t gregorian_calendar_is_valid_date         (cx::int_t year, cx::int_t month, cx::int_t day);

 

//===========================================================================

void epoch_to_jdn         (cx::int_t base_epoch_jdn, cx::int_t day_number, cx::int_t& jdn);

void epoch_to_date        (cx::int_t base_epoch_jdn, cx::int_t day_number, cx::int_t& year, cx::int_t& month, cx::int_t& day);

void epoch_to_day_of_week (cx::int_t base_epoch_jdn, cx::int_t day_number, cx::int_t& day_of_week);

void epoch_to_time        (                          cx::int_t daysecond_number, cx::int_t& hour, cx::int_t& minute, cx::int_t& second);

 

//===========================================================================

cx::int_t epoch_second_get_day_number       (cx::time_t epoch_second);

cx::int_t epoch_second_get_daysecond_number (cx::time_t epoch_second);

 

void epoch_second_to_jdn         (cx::int_t base_epoch_jdn, cx::time_t epoch_second, cx::int_t& jdn);

void epoch_second_to_datetime    (cx::int_t base_epoch_jdn, cx::time_t epoch_second, cx::int_t& year, cx::int_t& month, cx::int_t& day, cx::int_t& day_of_week, cx::int_t& hour, cx::int_t& minute, cx::int_t& second);

void epoch_second_to_date        (cx::int_t base_epoch_jdn, cx::time_t epoch_second, cx::int_t& year, cx::int_t& month, cx::int_t& day);

void epoch_second_to_day_of_week (cx::int_t base_epoch_jdn, cx::time_t epoch_second, cx::int_t& day_of_week);

void epoch_second_to_time        (                          cx::time_t epoch_second, cx::int_t& hour, cx::int_t& minute, cx::int_t& second);

void datetime_to_epoch_second    (cx::int_t year, cx::int_t month, cx::int_t day, cx::int_t hour, cx::int_t minute, cx::int_t second, cx::int_t base_epoch_jdn, cx::time_t& epoch_second);

 

//===========================================================================

cx::int_t unix_time_get_base_epoch_jdn (void);

 

void unix_time_to_jdn         (cx::time_t t, cx::int_t& jdn);

void unix_time_to_datetime    (cx::time_t t, cx::int_t& year, cx::int_t& month, cx::int_t& day, cx::int_t& day_of_week, cx::int_t& hour, cx::int_t& minute, cx::int_t& second);

void unix_time_to_date        (cx::time_t t, cx::int_t& year, cx::int_t& month, cx::int_t& day);

void unix_time_to_day_of_week (cx::time_t t, cx::int_t& day_of_week);

void unix_time_to_time        (cx::time_t t, cx::int_t& hour, cx::int_t& minute, cx::int_t& second);

void datetime_to_unix_time    (cx::int_t year, cx::int_t month, cx::int_t day, cx::int_t hour, cx::int_t minute, cx::int_t second, cx::time_t& t);

 

 

 

 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

void jdn_to_modified_jdn (cx::int_t jdn, cx::int_t& modified_jdn)

{

         /*

         # Modified JD

        

         Epoch:       0h Nov 17, 1858

         Calculation: JD 2400000.5

         */

 

         modified_jdn = jdn-2400001;

}

 

void jdn_to_truncated_jd (cx::int_t jdn, cx::int_t& truncated_jd)

{

         /*

         # Truncated JD

        

         Introduced by NASA in 1979

        

         Epoch:       0h May 24, 1968

         Calculation: floor (JD 2440000.5)

 

         cf:

         ceil () 소수점 이하 올림

         floor() 소수점 이하 버림

         round() 소수점 반올림

         */

 

         truncated_jd = jdn-2440001;

}

 

void jdn_to_lilian_date (cx::int_t jdn, cx::int_t& lilian_date)

{

         /*

         # Lilian date

 

         Count of days of the Gregorian calendar

        

         Epoch:       Oct 15, 1582

         Calculation: floor (JD 2299159.5)

         */

 

         lilian_date = jdn-2299160;

}

 

void jdn_to_unix_time_day_count (cx::int_t jdn, cx::int_t& unix_time_day_count)

{

         /*

         # Unix Time

 

         Count of seconds

 

         Epoch:       0h Jan 1, 1970

         Calculation: (JD 2440587.5) × 86400

         */

 

         unix_time_day_count = jdn-2440588;

}

 

 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

// Converting Gregorian calendar date to Julian Day Number(noon)

void gregorian_calendar_date_to_jdn (cx::int_t year, cx::int_t month, cx::int_t day, cx::int_t& jdn)

{

         // The algorithm is valid for all (possibly proleptic) Gregorian calendar dates after November 23, -4713.

 

         cx::int_t J;

         cx::int_t Y;

         cx::int_t M;

         cx::int_t D;

 

 

         Y = year;

         M = month;

         D = day;

 

        

         cx::int_t M1;

         cx::int_t Y1;

 

 

         M1 = (M - 14) / 12;

         Y1 = Y + 4800;

         J  = 1461 * (Y1 + M1) / 4 + 367 * (M - 2 - 12 * M1) / 12 - (3 * ((Y1 + M1 +100) / 100)) / 4 + D - 32075;

 

 

         jdn = J;

}

 

// Converting Julian calendar date to Julian Day Number(noon)

void julian_calendar_date_to_jdn (cx::int_t year, cx::int_t month, cx::int_t day, cx::int_t& jdn)

{

         // The algorithm is valid for all (possibly proleptic) Julian calendar years >= -4712, that is, for all JDN >= 0.

 

         cx::int_t J;

         cx::int_t Y;

         cx::int_t M;

         cx::int_t D;

 

 

         Y = year;

         M = month;

         D = day;

 

         J = 367 * Y - (7 * (Y + 5001 + (M - 9) / 7)) / 4 + (275 * M) / 9 + D + 1729777;

 

 

         jdn = J;

}

 

#if 0

void jdn_to_gregorian_calendar_date (cx::int_t jdn, cx::int_t& year, cx::int_t& month, cx::int_t& day)

{

         cx::int_t J;

         cx::int_t Y;

         cx::int_t M;

         cx::int_t D;

 

        

         J = jdn;

 

 

         cx::int_t p;

         cx::int_t q;

         cx::int_t r;

         cx::int_t s;

         cx::int_t t;

         cx::int_t u;

         cx::int_t v;

 

 

         p = J + 68569;

         q = 4*p/146097;

         r = p - (146097*q + 3)/4;

         s = 4000*(r+1)/1461001;

         t = r - 1461*s/4 + 31;

         u = 80*t/2447;

         v = u/11;

 

         Y = 100*(q-49)+s+v;

         M = u + 2 - 12*v;

         D = t - 2447*u/80;

 

         year  = Y;

         month = M;

         day   = D;

}

#endif

 

void jdn_to_gregorian_calendar_date (cx::int_t jdn, cx::int_t& year, cx::int_t& month, cx::int_t& day)

{

         const cx::int_t y = 4716;

         const cx::int_t j = 1401;

         const cx::int_t m = 2;

         const cx::int_t n = 12;

         const cx::int_t r = 4;

         const cx::int_t p = 1461;

         const cx::int_t v = 3;

         const cx::int_t u = 5;

         const cx::int_t s = 153;

         const cx::int_t w = 2;

         const cx::int_t B = 274277;

         const cx::int_t C = -38;

 

         cx::int_t J;

         cx::int_t Y;

         cx::int_t M;

         cx::int_t D;

 

 

         J = jdn;

 

 

         cx::int_t f;

         cx::int_t e;

         cx::int_t g;

         cx::int_t h;

 

         f = J + j + (((4 * J + B) / 146097) * 3) / 4 + C;

         e = r * f + v;

         g = (e % p) / r;

         h = u * g + w;

        

         D = (h % s) / u  + 1;

         M = (h / s + m) % n + 1;

         Y = (e / p) - y + (n + m - M) / n;

 

 

         year  = Y;

         month = M;

         day   = D;

}

 

void jdn_to_julian_calendar_date (cx::int_t jdn, cx::int_t& year, cx::int_t& month, cx::int_t& day)

{

         const cx::int_t y = 4716;

         const cx::int_t j = 1401;

         const cx::int_t m = 2;

         const cx::int_t n = 12;

         const cx::int_t r = 4;

         const cx::int_t p = 1461;

         const cx::int_t v = 3;

         const cx::int_t u = 5;

         const cx::int_t s = 153;

         const cx::int_t w = 2;

         const cx::int_t B = 274277;

         const cx::int_t C = -38;

 

 

         cx::int_t J;

         cx::int_t Y;

         cx::int_t M;

         cx::int_t D;

 

 

         J = jdn;

 

 

         cx::int_t f;

         cx::int_t e;

         cx::int_t g;

         cx::int_t h;

 

         f = J + j;

         e = r * f + v;

         g = (e % p) / r;

         h = u * g + w;

        

         D = (h % s) / u  + 1;

         M = (h / s + m) % n + 1;

         Y = (e / p) - y + (n + m - M) / n;

 

 

         year  = Y;

         month = M;

         day   = D;

}

 

 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

cx::int_t calendar_date_from_1582_10_05_to_1582_10_14 (cx::int_t year, cx::int_t month, cx::int_t day)

{

         cx::int_t from_1582_10_05_to_1582_10_14;

 

 

 

         from_1582_10_05_to_1582_10_14 = 0;

         if     (year< 1582)

         {

                  from_1582_10_05_to_1582_10_14 = -1;

         }

         else if (year==1582)

         {

                  if      (month <  10)

                  {

                           from_1582_10_05_to_1582_10_14 = -1;

                  }

                  else if (month == 10)

                  {

                           if      (day <= 4)

                           {

                                   from_1582_10_05_to_1582_10_14 = -1;

                           }

                           else if (day >= 15)

                           {

                                   from_1582_10_05_to_1582_10_14 = 1;

                           }

                  }

                  else if (month >  10)

                  {

                           from_1582_10_05_to_1582_10_14 = 1;

                  }

         }

         else if (year> 1582)

         {

                  from_1582_10_05_to_1582_10_14 = 1;

         }

 

 

         return from_1582_10_05_to_1582_10_14;

}

 

cx::bool_t calendar_date_to_jdn (cx::int_t year, cx::int_t month, cx::int_t day, cx::int_t& jdn)

{

         cx::int_t from_1582_10_05_to_1582_10_14;

 

 

 

         from_1582_10_05_to_1582_10_14 = calendar_date_from_1582_10_05_to_1582_10_14(year,month,day);

 

         if      (0> from_1582_10_05_to_1582_10_14)

         {

                  julian_calendar_date_to_jdn    (year,month,day, jdn);

         }

         else if (0==from_1582_10_05_to_1582_10_14)

         {

                  return false;

         }

         else if (0< from_1582_10_05_to_1582_10_14)

         {

                  gregorian_calendar_date_to_jdn (year,month,day, jdn);

         }

 

         return true;

}

 

void jdn_to_calendar_date (cx::int_t jdn, cx::int_t& year, cx::int_t& month, cx::int_t& day)

{

         // jdn: 2299160 = 1582-10-04 Julian Calendar Date

         // jdn: 2299161 = 1582-10-15 Gregorian Calendar Date

 

         if (jdn<=2299160)

         {

                  jdn_to_julian_calendar_date    (jdn, year,month,day);

         }

         else

         {

                  jdn_to_gregorian_calendar_date (jdn, year,month,day);

         }

}

 

 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

cx::int_t us_get_day_of_week (cx::int_t jdn)

{

         /*

         W1 = mod(J + 1, 7)

 

         0=Sun

         1=Mon

         2=Tue

         3=Wed

         4=Thu

         5=Fri

         6=Sat

         */

 

         return (jdn + 1) % 7;

}

 

cx::int_t iso_get_day_of_week (cx::int_t jdn)

{

         /*

         W0 = mod (J, 7) + 1

 

         1=Mon

         2=Tue

         3=Wed

         4=Thu

         5=Fri

         6=Sat

         7=Sun

         */

 

         return (jdn % 7) + 1;

}

 

 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

cx::bool_t gregorian_calendar_is_leap_year (cx::int_t year)

{

         if ( (0==(year%400))

              ||

              (0!=(year%100) && 0==(year%4)) )

         {

                  return true;

         }

 

         return false;

}

 

cx::bool_t gregorian_calendar_get_last_day_of_month (cx::int_t year, cx::int_t month, cx::int_t& day)

{

         cx::int_t month_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

 

 

         if (gregorian_calendar_is_leap_year(year))

         {

                  month_days[1] = 29;

         }

 

        

         if ( !( 0<month && month<13) )

         {

                  return false;

         }

 

 

         day = month_days[month-1];

 

         return true;

}

 

cx::bool_t gregorian_calendar_is_valid_date (cx::int_t year, cx::int_t month, cx::int_t day)

{

         cx::int_t last_day_of_month;

 

 

 

         if (false==gregorian_calendar_get_last_day_of_month(year, month, last_day_of_month))

         {

                  return false;

         }

 

         if ( day < 0 || day > last_day_of_month )

         {

                  return false;

         }

 

         return true;

}

 

 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

void epoch_to_jdn (cx::int_t base_epoch_jdn, cx::int_t day_number, cx::int_t& jdn)

{       

         jdn = base_epoch_jdn + day_number;

}

 

void epoch_to_date (cx::int_t base_epoch_jdn, cx::int_t day_number, cx::int_t& year, cx::int_t& month, cx::int_t& day)

{

         cx::int_t jdn;

 

        

         epoch_to_jdn(base_epoch_jdn, day_number, jdn);

        

 

         jdn_to_gregorian_calendar_date(jdn, year, month, day);

}

 

void epoch_to_day_of_week (cx::int_t base_epoch_jdn, cx::int_t day_number, cx::int_t& day_of_week)

{

         cx::int_t jdn;

 

        

         epoch_to_jdn(base_epoch_jdn, day_number, jdn);

        

 

         day_of_week = us_get_day_of_week(jdn);

}

 

void epoch_to_time (cx::int_t daysecond_number, cx::int_t& hour, cx::int_t& minute, cx::int_t& second)

{

         hour   =  daysecond_number / 3600;

         minute = (daysecond_number % 3600) / 60;

         second = (daysecond_number % 3600) % 60;

}

 

 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

cx::int_t epoch_second_get_day_number (cx::time_t epoch_second)

{

         const cx::int_t second_per_day = 86400; // 24*60*60;

        

         cx::int_t day_number;

 

 

         day_number = static_cast<cx::int_t>(epoch_second / second_per_day);

 

 

         return day_number;

}

 

cx::int_t epoch_second_get_daysecond_number (cx::time_t epoch_second)

{

         const cx::int_t second_per_day = 86400; // 24*60*60;

        

         cx::int_t daysecond_number;

 

 

         daysecond_number = static_cast<cx::int_t>(epoch_second % second_per_day);

 

 

         return daysecond_number;

}

 

//===========================================================================

void epoch_second_to_jdn (cx::int_t base_epoch_jdn, cx::time_t epoch_second, cx::int_t& jdn)

{

         cx::int_t day_number;

 

        

         day_number = epoch_second_get_day_number(epoch_second);

        

 

         epoch_to_jdn(base_epoch_jdn, day_number, jdn);

}

 

void epoch_second_to_datetime (cx::int_t base_epoch_jdn, cx::time_t epoch_second, cx::int_t& year, cx::int_t& month, cx::int_t& day, cx::int_t& day_of_week, cx::int_t& hour, cx::int_t& minute, cx::int_t& second)

{

         cx::int_t day_number;

         cx::int_t daysecond_number;

        

         cx::int_t jdn;

 

 

         day_number       = epoch_second_get_day_number      (epoch_second);

         daysecond_number = epoch_second_get_daysecond_number(epoch_second);

        

 

         epoch_to_jdn(base_epoch_jdn, day_number, jdn);

 

        

         jdn_to_gregorian_calendar_date(jdn, year, month, day);

         day_of_week = us_get_day_of_week(jdn);

 

        

         epoch_to_time(daysecond_number, hour, minute, second);

}

 

void epoch_second_to_date (cx::int_t base_epoch_jdn, cx::time_t epoch_second, cx::int_t& year, cx::int_t& month, cx::int_t& day)

{

         cx::int_t day_number;

        

         cx::int_t jdn;

 

 

         day_number = epoch_second_get_day_number(epoch_second);

        

 

         epoch_to_jdn(base_epoch_jdn, day_number, jdn);

 

        

         jdn_to_gregorian_calendar_date(jdn, year, month, day);

}

 

void epoch_second_to_day_of_week (cx::int_t base_epoch_jdn, cx::time_t epoch_second, cx::int_t& day_of_week)

{

         cx::int_t day_number;

        

         cx::int_t jdn;

 

 

         day_number = epoch_second_get_day_number(epoch_second);

 

        

         epoch_to_jdn(base_epoch_jdn, day_number, jdn);

 

        

         day_of_week = us_get_day_of_week(jdn);

}

 

void epoch_second_to_time (cx::time_t epoch_second, cx::int_t& hour, cx::int_t& minute, cx::int_t& second)

{

         cx::int_t daysecond_number;

 

 

         daysecond_number = epoch_second_get_daysecond_number(epoch_second);

        

 

         epoch_to_time(daysecond_number, hour, minute, second);

}

 

void datetime_to_epoch_second (cx::int_t year, cx::int_t month, cx::int_t day, cx::int_t hour, cx::int_t minute, cx::int_t second, cx::int_t base_epoch_jdn, cx::time_t& epoch_second)

{

         const cx::int_t second_per_day = 86400; // 24*60*60;

 

         cx::int_t jdn;

 

         cx::time_t day_number;

         cx::time_t daysecond_number;

 

 

         gregorian_calendar_date_to_jdn (year, month, day, jdn);

 

        

         day_number       = jdn - base_epoch_jdn;

         daysecond_number = hour*3600 + minute*60 + second;

        

 

         epoch_second = day_number*second_per_day + daysecond_number;

}

 

 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

cx::int_t unix_time_get_base_epoch_jdn (void)

{

         const cx::int_t base_jdn = 2440588; // 1970 01 01 12:00:00

 

 

         return base_jdn;

}

 

void unix_time_to_jdn (cx::time_t t, cx::int_t& jdn)

{

         epoch_second_to_jdn (unix_time_get_base_epoch_jdn(), t, jdn);

}

 

void unix_time_to_datetime (cx::time_t t, cx::int_t& year, cx::int_t& month, cx::int_t& day, cx::int_t& day_of_week, cx::int_t& hour, cx::int_t& minute, cx::int_t& second)

{

         epoch_second_to_datetime (unix_time_get_base_epoch_jdn(), t, year, month, day, day_of_week, hour, minute, second);

}

 

void unix_time_to_date (cx::time_t t, cx::int_t& year, cx::int_t& month, cx::int_t& day)

{

         epoch_second_to_date (unix_time_get_base_epoch_jdn(), t, year, month, day);

}

 

void unix_time_to_day_of_week (cx::time_t t, cx::int_t& day_of_week)

{

         epoch_second_to_day_of_week (unix_time_get_base_epoch_jdn(), t, day_of_week);

}

 

void unix_time_to_time (cx::time_t t, cx::int_t& hour, cx::int_t& minute, cx::int_t& second)

{

         epoch_second_to_time (t, hour, minute, second);

}

 

void datetime_to_unix_time (cx::int_t year, cx::int_t month, cx::int_t day, cx::int_t hour, cx::int_t minute, cx::int_t second, cx::time_t& t)

{

         datetime_to_epoch_second (year, month, day, hour, minute, second, unix_time_get_base_epoch_jdn(), t);

}


 

 

/////////////////////////////////////////////////////////////////////////////

//===========================================================================

void show (

         cx::int_t jdn        ,

         cx::int_t year       ,

         cx::int_t month      ,

         cx::int_t day        ,

         cx::int_t day_of_week,

         cx::int_t hour       ,

         cx::int_t minute     ,

         cx::int_t second

         )

{

         cx::int_t modified_jdn;

         cx::int_t truncated_jd;

         cx::int_t lilian_date;

         cx::int_t unix_time_day_count;

 

 

         jdn_to_modified_jdn       (jdn, modified_jdn       );

         jdn_to_truncated_jd       (jdn, truncated_jd       );

         jdn_to_lilian_date        (jdn, lilian_date        );

         jdn_to_unix_time_day_count(jdn, unix_time_day_count);

 

         printf ("%+05d-%02d-%02d(%d) %02d:%02d:%02d = %8d / MJDN=%8d, TJD=%8d, LILIAN=%8d, UNIX=%8d \r\n",

                  year,month,day, day_of_week,

                  hour, minute, second,

                  jdn,

                  modified_jdn       ,

                  truncated_jd       ,

                  lilian_date        ,

                  unix_time_day_count

                  );

}

 

int _tmain(int argc, _TCHAR* argv[])

{

         cx::int_t jdn         = 0;

         cx::int_t year        = 0;

         cx::int_t month       = 0;

         cx::int_t day         = 0;

         cx::int_t day_of_week = 0;

         cx::int_t hour        = 0;

         cx::int_t minute      = 0;

         cx::int_t second      = 0;

 

         cx::int_t day_count = 0;

 

         cx::time_t t;

 

 

         //-----------------------------------------------------------------------

         // 12h Jan 1, 4713 BC

         jdn = 0;

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

 

         year  =-4712;

         month =1;

         day   =1;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         printf ("\r\n");

 

 

 

         //-----------------------------------------------------------------------

         // BC 1

         year  =0;

         month =1;

         day   =1;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         printf ("\r\n");

 

 

 

         //-----------------------------------------------------------------------

         // 1 AD

         year  =1;

         month =1;

         day   =1;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         printf ("\r\n");

 

 

         //-----------------------------------------------------------------------

         // AD 2

         year  =2;

         month =1;

         day   =1;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         printf ("\r\n");

 

 

         //-----------------------------------------------------------------------

         jdn = 2299161-2;

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

 

         jdn = 2299161-1;

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

 

         jdn = 2299161;

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

 

         jdn = 2299161+1;

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

 

 

         year  =1582;

         month =10;

         day   = 3;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

 

         year  =1582;

         month =10;

         day   = 4;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

 

         // Lilian date : Oct 15, 1582 = floor (JD 2299159.5) ; Count of days of the Gregorian calendar

         year  =1582;

         month =10;

         day   =15;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

 

         year  =1582;

         month =10;

         day   =16;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         printf ("\r\n");

 

 

         //-----------------------------------------------------------------------

         // Reduced JD (JD - 2400000)

         year  =1858;

         month =11;

         day   =16;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         printf ("\r\n");

 

 

         //-----------------------------------------------------------------------

         // Modified JD: 0h Nov 17, 1858 = (JD 2400000.5)

         year  =1858;

         month =11;

         day   =17;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         printf ("\r\n");

 

 

         //-----------------------------------------------------------------------

         // Truncated JD: 0h May 24, 1968 = floor (JD 2440000.5) ; Introduced by NASA in 1979

         year  =1968;

         month =5;

         day   =24;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         printf ("\r\n");

 

 

         //-----------------------------------------------------------------------

         // Unix Time: 0h Jan 1, 1970 = (JD 2440587.5) × 86400

         year  =1970;

         month =1;

         day   =1;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         printf ("\r\n");

 

 

         //-----------------------------------------------------------------------

         year  =2000;

         month =1;

         day   =1;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         printf ("\r\n");

 

 

 

         //-----------------------------------------------------------------------

         year  =2018;

         month =10;

         day   =9;

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         printf ("\r\n");

 

 

         //-----------------------------------------------------------------------

         t = time(NULL) + 9*60*60;

 

         day_count = static_cast<cx::int_t>(t / 86400);

         printf ("time() / 86400 = %d \r\n", day_count);

 

         unix_time_to_jdn     (t, jdn);

         unix_time_to_datetime(t, year,month,day, day_of_week, hour, minute, second);

 

         show (jdn, year, month, day, day_of_week, hour, minute, second);

 

         calendar_date_to_jdn(year,month,day, jdn); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

         jdn_to_calendar_date(jdn, year,month,day); day_of_week = us_get_day_of_week(jdn); show(jdn, year, month, day, day_of_week, hour, minute, second);

 

         printf ("\r\n");

 

         return 0;

}

 

/*

-4712-01-01(1) 00:00:00 =        0 / MJDN=-2400001, TJD=-2440001, LILIAN=-2299160, UNIX=-2440588

-4712-01-01(1) 00:00:00 =        0 / MJDN=-2400001, TJD=-2440001, LILIAN=-2299160, UNIX=-2440588

 

+0000-01-01(4) 00:00:00 =  1721058 / MJDN= -678943, TJD= -718943, LILIAN= -578102, UNIX= -719530

+0000-01-01(4) 00:00:00 =  1721058 / MJDN= -678943, TJD= -718943, LILIAN= -578102, UNIX= -719530

 

+0001-01-01(6) 00:00:00 =  1721424 / MJDN= -678577, TJD= -718577, LILIAN= -577736, UNIX= -719164

+0001-01-01(6) 00:00:00 =  1721424 / MJDN= -678577, TJD= -718577, LILIAN= -577736, UNIX= -719164

 

+0002-01-01(0) 00:00:00 =  1721789 / MJDN= -678212, TJD= -718212, LILIAN= -577371, UNIX= -718799

+0002-01-01(0) 00:00:00 =  1721789 / MJDN= -678212, TJD= -718212, LILIAN= -577371, UNIX= -718799

 

+1582-10-03(3) 00:00:00 =  2299159 / MJDN= -100842, TJD= -140842, LILIAN=      -1, UNIX= -141429

+1582-10-04(4) 00:00:00 =  2299160 / MJDN= -100841, TJD= -140841, LILIAN=       0, UNIX= -141428

+1582-10-15(5) 00:00:00 =  2299161 / MJDN= -100840, TJD= -140840, LILIAN=       1, UNIX= -141427

+1582-10-16(6) 00:00:00 =  2299162 / MJDN= -100839, TJD= -140839, LILIAN=       2, UNIX= -141426

+1582-10-03(3) 00:00:00 =  2299159 / MJDN= -100842, TJD= -140842, LILIAN=      -1, UNIX= -141429

+1582-10-04(4) 00:00:00 =  2299160 / MJDN= -100841, TJD= -140841, LILIAN=       0, UNIX= -141428

+1582-10-15(5) 00:00:00 =  2299161 / MJDN= -100840, TJD= -140840, LILIAN=       1, UNIX= -141427

+1582-10-16(6) 00:00:00 =  2299162 / MJDN= -100839, TJD= -140839, LILIAN=       2, UNIX= -141426

 

+1858-11-16(2) 00:00:00 =  2400000 / MJDN=      -1, TJD=  -40001, LILIAN=  100840, UNIX=  -40588

+1858-11-16(2) 00:00:00 =  2400000 / MJDN=      -1, TJD=  -40001, LILIAN=  100840, UNIX=  -40588

 

+1858-11-17(3) 00:00:00 =  2400001 / MJDN=       0, TJD=  -40000, LILIAN=  100841, UNIX=  -40587

+1858-11-17(3) 00:00:00 =  2400001 / MJDN=       0, TJD=  -40000, LILIAN=  100841, UNIX=  -40587

 

+1968-05-24(5) 00:00:00 =  2440001 / MJDN=   40000, TJD=       0, LILIAN=  140841, UNIX=    -587

+1968-05-24(5) 00:00:00 =  2440001 / MJDN=   40000, TJD=       0, LILIAN=  140841, UNIX=    -587

 

+1970-01-01(4) 00:00:00 =  2440588 / MJDN=   40587, TJD=     587, LILIAN=  141428, UNIX=       0

+1970-01-01(4) 00:00:00 =  2440588 / MJDN=   40587, TJD=     587, LILIAN=  141428, UNIX=       0

 

+2000-01-01(6) 00:00:00 =  2451545 / MJDN=   51544, TJD=   11544, LILIAN=  152385, UNIX=   10957

+2000-01-01(6) 00:00:00 =  2451545 / MJDN=   51544, TJD=   11544, LILIAN=  152385, UNIX=   10957

 

+2018-10-09(2) 00:00:00 =  2458401 / MJDN=   58400, TJD=   18400, LILIAN=  159241, UNIX=   17813

+2018-10-09(2) 00:00:00 =  2458401 / MJDN=   58400, TJD=   18400, LILIAN=  159241, UNIX=   17813

 

time() / 86400 = 17809

+2018-10-05(5) 16:30:50 =  2458397 / MJDN=   58396, TJD=   18396, LILIAN=  159237, UNIX=   17809

+2018-10-05(5) 16:30:50 =  2458397 / MJDN=   58396, TJD=   18396, LILIAN=  159237, UNIX=   17809

+2018-10-05(5) 16:30:50 =  2458397 / MJDN=   58396, TJD=   18396, LILIAN=  159237, UNIX=   17809

 

*/

 


Posted by 셈말짓기 :

std::regx

2017. 8. 25. 09:09 from 셈말짓기/C and C++

#include "stdafx.h"

 

#include <regex>

#include <sstream>

#include <vector>

#include <iostream>

#include <vector>

 

void t4()

{

         //-----------------------------------------------------------------------

         std::string expression;

 

 

         //  ECMAScript : Special Keyword ^ $ \ . * + ? ( ) [ ] { } |

         expression = "\\\"([^\\\"]*)\\\"=([NR])";

         //       expression = R"STRING_LITERAL_DELIMITER(\"([^\"]*)\"=([NR]))STRING_LITERAL_DELIMITER";

         expression = R"d(\"([^\"]*)\"=([NR]))d";

         //       expression = R"d(\"([^\"]*)\")d";

 

 

         //-----------------------------------------------------------------------

         std::string text;

         std::string element;

 

         text = "  \"1A(:B/C)\":N, \"2AB,C\":R\"3A(:B/C)\":R, \"aa\"  ";

         text = "  \"21\"=N, \"22\"=R, \"23\"=R, \"24\"=x";

 

 

 

         //-----------------------------------------------------------------------

         std::vector<int> ei; // element index

 

 

         ei.push_back(1);

         ei.push_back(2);

         ei.push_back(3);

 

 

         //-----------------------------------------------------------------------

         std::regex                       r(expression);

         const std::sregex_token_iterator end;

         std::sregex_token_iterator       i(text.begin(), text.end(), r, ei);

 

 

         std::cout << expression << std::endl;

         std::cout << text << std::endl;

         while (i != end)

         {

                  element = *i++;

 

                  std::cout << element << std::endl;

         }

}

 

void t5()

{

         //-----------------------------------------------------------------------

         std::string expression;

 

 

         expression = R"d(\"([^\"]*)\"=([NR]))d";

 

 

         //-----------------------------------------------------------------------

         std::string text;

         std::string element;

 

 

         text = "  \"21\"=N, \"22\"=R, \"23\"=R, \"24\"=x";

 

 

         //-----------------------------------------------------------------------

         std::regex      r(expression);

         std::smatch     m;

         std::ssub_match sm;

 

         std::string value;

 

         std::size_t i;

         std::size_t count;

 

 

         value = text;

 

         while (std::regex_search(value, m, r))

         {

                  count = m.size();

 

                  for (i = 0u; i < count; i++)

                  {

                           sm = m[i];

 

                           if (sm.matched)

                           {

                                   element = sm.str();

 

                                   std::cout << i << " = " << element << std::endl;

                           }

                  }

 

                  value = m.suffix();

         }

}

 

int _tmain(int argc, _TCHAR* argv[])

{

         t5();

 

 

         return 0;

}

 

Posted by 셈말짓기 :


doxygen_template.zip


Posted by 셈말짓기 :

Image지원되는 RTF Editor입니다.


WTL기반으로 작성되었습니다.

COM 인터페이스로 이미지를 보여지게 하는 코드를 주서다가 만들었습니다.

그런데, RichEdit 8.0 부터는 이미지가 추가 API가 제공 됩니다. 








rtf_editor.zip





Posted by 셈말짓기 :

원격 디버깅으로 테스트 하다가

실행 못한다고 나오길레..

당연히 c-runtime dll들을 복사 해주면 될 줄 알았더니..

안되었음..

 

검색질 해보니

vs2008 sp1에서 manifest versions 가 업데이트 안되서

Microsoft.VC90.DebugCRT.manifest을 수정하면 된다고 함.

 

version="9.0.30729.4148"을 version="9.0.21022.8"으로 변경..

 

잘 됨.. -_-;

 

vs2008이 옛날꺼 되었어도 좀 고쳐라 MS..

 

http://stackoverflow.com/questions/3515450/installing-ms-debug-dlls-for-remote-debugging

 

참고..

- 원격 디버깅 서버 프로그램 경로

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger\msvsmon.exe

 

- DLL경로

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist

Posted by 셈말짓기 :