维基百科 解释:https://en.wikipedia.org/wiki/Julian_day
主要是天文学在用,在一个周期内以日计数计算。
Linux多线程编程工具库liblmp_tool github: https://github.com/Dwyane05/liblmp_tool
Date类分析:
头文件:;
/*
* Use of this source code is governed by a BSD-style license
* that can be found in the License file.
*
* Date.h
* Created on: May 30, 2019
* Author: cuiyongfei
*/
#ifndef LMP_TOOL_DATE_H
#define LMP_TOOL_DATE_H
#include "copyable.h"
#include "Common.h"
struct tm;
namespace lmp_tool
{
///
/// Date in Gregorian calendar.
///
/// This class is immutable.
/// It's recommended to pass it by value, since it's passed in register on x64.
///
class Date : public lmp_tool::copyable
{
public:
struct YearMonthDay
{
int year; // [1900..2500]
int month; // [1..12]
int day; // [1..31]
};
static const int kDaysPerWeek = 7;
static const int kJulianDayOf1970_01_01;
///
/// Constucts an invalid Date.
///
Date()
: julianDayNumber_(0)
{}
///
/// Constucts a yyyy-mm-dd Date.
///
/// 1 <= month <= 12
Date(int year, int month, int day);
///
/// Constucts a Date from Julian Day Number.
///
explicit Date(int julia