remwharead/docs/time_8hpp.html
2019-11-02 08:13:06 +01:00

175 lines
11 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://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.15"/>
<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.8.5</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<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;chrono&gt;</code><br />
<code>#include &lt;string&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:a688dc03822f9d2a84cdd373e708fddd3"><td class="memItemLeft" align="right" valign="top">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:a688dc03822f9d2a84cdd373e708fddd3"><td class="mdescLeft">&#160;</td><td class="mdescRight">Convert ISO 8601 or SQLite time-string to time_point. <a href="time_8cpp.html#a688dc03822f9d2a84cdd373e708fddd3">More...</a><br /></td></tr>
<tr class="separator:a688dc03822f9d2a84cdd373e708fddd3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa8ea3d4828baa1b051563992f83b1b58"><td class="memItemLeft" align="right" valign="top">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:aa8ea3d4828baa1b051563992f83b1b58"><td class="mdescLeft">&#160;</td><td class="mdescRight">Convert time_point to ISO 8601 or SQLite time-string. <a href="time_8cpp.html#aa8ea3d4828baa1b051563992f83b1b58">More...</a><br /></td></tr>
<tr class="separator:aa8ea3d4828baa1b051563992f83b1b58"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Function Documentation</h2>
<a id="file_a688dc03822f9d2a84cdd373e708fddd3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#file_a688dc03822f9d2a84cdd373e708fddd3">&#9670;&nbsp;</a></span>string_to_timepoint()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">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="l00030"></a><span class="lineno"> 30</span>&#160;{</div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160; std::stringstream sstime(strtime);</div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span>&#160; <span class="keyword">struct </span>std::tm tm = {};</div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span>&#160; tm.tm_isdst = -1; <span class="comment">// Detect daylight saving time.</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160; <span class="keywordflow">if</span> (sqlite)</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-%d %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; <span class="keywordflow">else</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160; {</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</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="l00041"></a><span class="lineno"> 41</span>&#160; }</div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160; std::time_t time = timelocal(&amp;tm); <span class="comment">// Assume time is local.</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160; <span class="keywordflow">return</span> system_clock::from_time_t(time);</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>&#160;}</div></div><!-- fragment -->
</div>
</div>
<a id="file_aa8ea3d4828baa1b051563992f83b1b58"></a>
<h2 class="memtitle"><span class="permalink"><a href="#file_aa8ea3d4828baa1b051563992f83b1b58">&#9670;&nbsp;</a></span>timepoint_to_string()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">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="l00047"></a><span class="lineno"> 47</span>&#160;{</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160; constexpr std::uint16_t bufsize = 32;</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160; std::time_t time = system_clock::to_time_t(tp);</div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160; std::tm *tm;</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160; tm = std::localtime(&amp;time);</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160;</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160; array&lt;char, bufsize&gt; buffer = {};</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160;</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160; <span class="keywordflow">if</span> (sqlite)</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160; {</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160; std::strftime(buffer.begin(), bufsize, <span class="stringliteral">&quot;%F %T&quot;</span>, tm);</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">else</span></div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160; {</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>&#160; std::strftime(buffer.begin(), bufsize, <span class="stringliteral">&quot;%FT%T&quot;</span>, tm);</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160; }</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160;</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160; <span class="keywordflow">return</span> buffer.begin();</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</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.15
</small></address>
</body>
</html>