<div dir="ltr">Jerry et al,<div><br></div><div>I also checked this using only NCL and 32-bit integer math. Please see the attached NCL script, and check my math. The result agrees with cd_calendar.</div><div><br></div><div>Please notice that there are two different calendar systems involved. Years 0001 to 1581 are in the Julian calendar, and 1583 to 2018 are in the Gregorian calendar. This script breaks up the full interval into several segments, and computes the exact number of hours in each segment, using the correct set of calendar rules for each segment. This is the result:<br><br><font face="monospace, monospace">(0) nhour_julian = 13859040<br>(0) nhour_1582 = 8520<br>(0) nhour_greg = 3813144<br>(0) nhour_2018 = 1824<br>(0) nhour_march_18 = 14<br>(0)<br>(0) Total hours = 17682542<br>(0) Target = 17682542 hours since 0001-01-01 00:00<br></font><br>However, the Julian calendar is not a proper standard, and there are historical variations. See the Wikipedia article. This may have led to varying interpretations in different software packages, and there are also known bugs in some calendar software. My script uses the Udunits interpretation, which I think is the same as cd_calendar.</div><div><br></div><div>Best practice is to completely avoid the Julian calendar, and use only modern Gregorian origin dates (1583 or later) with modern data, such as:</div><div><br></div><div>"days since 1900-01-01"</div><div>"hours since 2000-01-01"</div><div><br></div><div>To avoid future problems, I recommend that you ask your data source to change their files to use only the Gregorian calendar and modern origin dates.</div><div><br></div><div>--Dave</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 16, 2018 at 8:22 AM, Beáta Szabó-Takács <span dir="ltr"><<a href="mailto:szabo.b@czechglobe.cz" target="_blank">szabo.b@czechglobe.cz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div id="gmail-m_8849646739925447487divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p style="margin-top:0px;margin-bottom:0px">Dear Jerry,</p>
<p style="margin-top:0px;margin-bottom:0px"><br>
</p>
<p style="margin-top:0px;margin-bottom:0px">I checked your date conversion in Matlab as well by the following way:</p>
<p style="margin-top:0px;margin-bottom:0px">I divided <span>17682542</span> hours by 24 to get days (736772.6 days). I calculated the serial date number of 0001.01.01 00:00:00 by datenum function which is 372 days. I added up these days (<span>736772.6</span> +
372) and used this value in datevec function which resulted 2018.03.20 14:00. In my view, the NCL cd_calendar function is correct because in Gregorian calendar there are no double leap years (372 days).</p>
<p style="margin-top:0px;margin-bottom:0px">Furthermore, I checked the date -d <span>
"<span><span><span>17682542 hours 0001-01-01 00:00"</span></span></span> +"%Y-%m-%d %H:%M"</span> function on different linux system and I got different date values:</p>
<p style="margin-top:0px;margin-bottom:0px">Debian (GNU/Lin 8): 2018-03-20 13:43</p>
<p style="margin-top:0px;margin-bottom:0px">Ubuntu 14.04: 2018-03-20 14:02</p>
<p style="margin-top:0px;margin-bottom:0px">Linux 3.10.0: 2018-03-20 14:00.</p>
<p style="margin-top:0px;margin-bottom:0px"><br>
</p>
<p style="margin-top:0px;margin-bottom:0px">I hope I could help you!</p>
<p style="margin-top:0px;margin-bottom:0px">Best regards,</p>
<p style="margin-top:0px;margin-bottom:0px">Beata<br>
</p>
</div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_8849646739925447487divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> ncl-talk <<a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.edu</a>> on behalf of Jianyu Liu <<a href="mailto:jerry_leo@msn.com" target="_blank">jerry_leo@msn.com</a>><br>
<b>Sent:</b> Monday, April 9, 2018 10:46:18 AM<br>
<b>To:</b> <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
<b>Subject:</b> [ncl-talk] Date calculation of hours since "0001-01-01 00:00"</font>
<div> </div>
</div>
<div dir="ltr">
<div id="gmail-m_8849646739925447487x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif">
<p style="margin-top:0px;margin-bottom:0px"></p>
<div>Hi, <br>
<br>
Just noticed the inconsistent of <span>date calculation of hours since "0001-01-01 00:00"</span><span>,
<span>there are 2 days difference between NCL and other script/command, such as date, php.
</span><br>
<br>
Saying <span><span>"17682542 hours since 0001-01-01 00:00"</span></span>, NCL gave
<span><span><span>2018</span>-03-18 14:00</span></span>, Linux date command and php script gave
<span><span><span><span>2018</span>-03-20 14:00</span></span></span>. </span><span> Wondering who is correct.
<br>
<br>
Here are the output of NCL<br>
</span>
<blockquote><span>
<div>ncl 1> print (f->time) </div>
</span></blockquote>
<blockquote><span>
<div>Variable: time (file variable)</div>
</span><span>
<div>Type: double</div>
</span><span>
<div>Total Size: 8 bytes</div>
</span><span>
<div> 1 values</div>
</span><span>
<div>Number of Dimensions: 1</div>
</span><span>
<div>Dimensions and sizes: [time | 1]</div>
</span><span>
<div>Coordinates:</div>
</span><span>
<div> time: [17682542..17682542]</div>
</span><span>
<div>Number Of Attributes: 2</div>
</span><span>
<div> units : hours since 0001-01-01 00:00:00.0</div>
</span><span>
<div> calendar : standard</div>
</span><span>
<div>(0) 17682542</div>
</span><br>
<span>
<div>ncl 2> utc_date=cd_calendar(f->time,<wbr>0)</div>
</span><span>
<div>ncl 3> print(utc_date)</div>
</span><span>
<div>Variable: utc_date</div>
</span><span>
<div>Type: float</div>
</span><span>
<div>Total Size: 24 bytes</div>
</span><span>
<div> 6 values</div>
</span><span>
<div>Number of Dimensions: 2</div>
</span><span>
<div>Dimensions and sizes: [1] x [6]</div>
</span><span>
<div>Coordinates:</div>
</span><span>
<div>Number Of Attributes: 1</div>
</span><span>
<div> calendar : standard</div>
</span><span>
<div>(0,0) 2018</div>
</span><span>
<div>(0,1) 3</div>
</span><span>
<div>(0,2) 18</div>
</span><span>
<div>(0,3) 14</div>
</span><span>
<div>(0,4) 0</div>
</span><span>
<div>(0,5) 1.341105e-05</div>
</span></blockquote>
<span><span>Here are the output of date command</span><br>
<br>
date -d "<span><span><span>17682542 hours 0001-01-01 00:00"</span></span></span> +"%Y-%m-%d %H:%M"<br>
<br>
<span><span>2018</span>-03-20 14:00</span><br>
<br>
<span><span>Here are the output of</span></span> PHP<br>
<br>
ini_set('date.timezone', 'UTC');<br>
$t=strtotime('0001-01-01 +<span><span><span>17682542 hours</span></span></span>) ;<br>
<span></span></span><span></span> echo date('Y-m-d H:i', $t);<br>
<br>
2018-03-20 14:00<br>
<br>
Thanks for your time <br>
<br>
Regards<br>
<br>
Jerry<br></div></div></div></div></blockquote></div></div></div>