remwharead/docs/time_8hpp.html
2019-08-05 22:01:08 +02:00

175 lines
12 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>remwharead: include/time.hpp File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">remwharead
&#160;<span id="projectnumber">0.6.3</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="summary">
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">time.hpp File Reference</div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &lt;string&gt;</code><br />
<code>#include &lt;chrono&gt;</code><br />
</div>
<p><a href="time_8hpp_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ad6942f485c7b34b97451c50cadc9c4f8"><td class="memItemLeft" align="right" valign="top">const time_point&#160;</td><td class="memItemRight" valign="bottom"><b>remwharead::string_to_timepoint</b> (const string &amp;strtime, bool sqlite=false)</td></tr>
<tr class="memdesc:ad6942f485c7b34b97451c50cadc9c4f8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Convert ISO 8601 or SQLite time-string to time_point. <a href="time_8cpp.html#ad6942f485c7b34b97451c50cadc9c4f8">More...</a><br /></td></tr>
<tr class="separator:ad6942f485c7b34b97451c50cadc9c4f8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:afe40ba8b39335c4196c1b12139014e7d"><td class="memItemLeft" align="right" valign="top">const string&#160;</td><td class="memItemRight" valign="bottom"><b>remwharead::timepoint_to_string</b> (const time_point &amp;tp, bool sqlite=false)</td></tr>
<tr class="memdesc:afe40ba8b39335c4196c1b12139014e7d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Convert time_point to ISO 8601 or SQLite time-string. <a href="time_8cpp.html#afe40ba8b39335c4196c1b12139014e7d">More...</a><br /></td></tr>
<tr class="separator:afe40ba8b39335c4196c1b12139014e7d"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Function Documentation</h2>
<a id="file_ad6942f485c7b34b97451c50cadc9c4f8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#file_ad6942f485c7b34b97451c50cadc9c4f8">&#9670;&nbsp;</a></span>string_to_timepoint()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">const time_point remwharead::string_to_timepoint </td>
<td>(</td>
<td class="paramtype">const string &amp;&#160;</td>
<td class="paramname"><em>strtime</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">bool&#160;</td>
<td class="paramname"><em>sqlite</em> = <code>false</code>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Convert ISO 8601 or SQLite time-string to time_point. </p>
<p>The SQLite format is <em>YY-MM-DD hh:mm:ss</em> instead of <em>YY-MM-DDThh:mm:ss</em>.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">strtime</td><td>Time string in ISO 8601 or SQLite format. </td></tr>
<tr><td class="paramname">sqlite</td><td>Is the string in SQLite format? </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160; {</div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160; std::stringstream sstime(strtime);</div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160; <span class="keyword">struct </span>std::tm tm = {};</div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160; tm.tm_isdst = -1; <span class="comment">// Detect daylight saving time.</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160; <span class="keywordflow">if</span> (sqlite)</div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160; {</div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span>&#160; sstime &gt;&gt; std::get_time(&amp;tm, <span class="stringliteral">&quot;%Y-%m-%d %T&quot;</span>);</div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span>&#160; }</div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160; <span class="keywordflow">else</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span>&#160; {</div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span>&#160; sstime &gt;&gt; std::get_time(&amp;tm, <span class="stringliteral">&quot;%Y-%m-%dT%T&quot;</span>);</div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160; }</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span>&#160; std::time_t time = timelocal(&amp;tm); <span class="comment">// Assume time is local.</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160; <span class="keywordflow">return</span> system_clock::from_time_t(time);</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160; }</div></div><!-- fragment -->
</div>
</div>
<a id="file_afe40ba8b39335c4196c1b12139014e7d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#file_afe40ba8b39335c4196c1b12139014e7d">&#9670;&nbsp;</a></span>timepoint_to_string()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">const string remwharead::timepoint_to_string </td>
<td>(</td>
<td class="paramtype">const time_point &amp;&#160;</td>
<td class="paramname"><em>tp</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">bool&#160;</td>
<td class="paramname"><em>sqlite</em> = <code>false</code>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Convert time_point to ISO 8601 or SQLite time-string. </p>
<p>The SQLite format is <em>YY-MM-DD hh:mm:ss</em> instead of <em>YY-MM-DDThh:mm:ss</em>.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">time_point</td><td>The std::chrono::system_clock::time_point. </td></tr>
<tr><td class="paramname">sqlite</td><td>Is the string in SQLite format? </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160; {</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>&#160; constexpr std::uint16_t bufsize = 32;</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>&#160; std::time_t time = system_clock::to_time_t(tp);</div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>&#160; std::tm *tm;</div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>&#160; tm = std::localtime(&amp;time);</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160; <span class="keywordtype">char</span> buffer[bufsize];</div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160; <span class="keywordflow">if</span> (sqlite)</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160; {</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160; std::strftime(buffer, bufsize, <span class="stringliteral">&quot;%F %T&quot;</span>, tm);</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160; }</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160; <span class="keywordflow">else</span></div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160; {</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160; std::strftime(buffer, bufsize, <span class="stringliteral">&quot;%FT%T&quot;</span>, tm);</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160; }</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>&#160;</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>&#160; <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><span class="keyword">const </span><span class="keywordtype">string</span><span class="keyword">&gt;</span>(buffer);</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160; }</div></div><!-- fragment -->
</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.14
</small></address>
</body>
</html>