<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4720737843399911294</id><updated>2026-08-24T01:40:53.515+09:00</updated><category term="Erlang"/><category term="Python"/><category term="Elixir"/><category term="Windows Vista"/><category term="FIRE"/><category term="Google chrome Extension"/><category term="JavaScript"/><category term="ruby"/><category term="RaspberryPi"/><category term="wxWidgets"/><category term="マグロウヒル大学演習シリーズ 微積分(上)"/><category term="Day.js"/><category term="雑記"/><category term="ASP.NET"/><category term="Eclipse"/><category term="ruby on rails"/><category term="Google"/><category term="TypeScript"/><category term="楽天ラッキーくじ"/><category term="Atom"/><category term="CSS"/><category term="Django"/><category term="Google SpreadSheet"/><category term="HTML"/><category term="IIS"/><category term="KingSoft"/><category term="Material Design"/><category term="Math"/><category term="MySQL"/><category term="OpenCV"/><category term="OpenXML"/><category term="Parse"/><category term="Struts"/><category term="Sublime Text"/><category term="VSCode"/><category term="YUI"/><category term="chromeOS"/><category term="cmake"/><category term="firefox"/><category term="iPhone App"/><category term="iconv-lite"/><category term="moto"/><category term="pytest"/><category term="vim"/><category term="ふるさと納税"/><category term="ラムダ計算"/><title type='text'>tomohikoのブログ</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>264</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-4342116927514439527</id><published>2025-07-27T09:20:00.004+09:00</published><updated>2025-07-27T09:20:58.173+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="マグロウヒル大学演習シリーズ 微積分(上)"/><title type='text'>P71 問62 （マグロウヒル大学演習シリーズ 微積分(上)）を解く．</title><content type='html'>&lt;div style=&quot;border: 1px solid #ccc; padding: 1em; margin-bottom: 1em; background-color: #f9f9f9;&quot;&gt;
  &lt;p style=&quot;font-weight: bold; margin-top: 0;&quot;&gt;問62&lt;/p&gt;
  &lt;p style=&quot;margin-bottom: 0;&quot;&gt;　$\lim_{n \to \infty} |u_{n+1}/u_n| = |a| &lt; 1$ ならば $\lim_{n \to \infty} u_n = 0$ であることを証明せよ．&lt;/p&gt;
&lt;/div&gt;

&lt;h2&gt;証明の方針&lt;/h2&gt;
&lt;p&gt;　これは級数の収束判定で用いられるダランベールの収束判定法の証明の一部と同じ考え方を使います。&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;$\lim_{n \to \infty} |u_{n+1}/u_n| = |a| &lt; 1$ という条件から、十分大きな $n$ に対して $|u_{n+1}/u_n|$ が1より小さい定数 $r$ で上から抑えられることを示します。&lt;/li&gt;
  &lt;li&gt;具体的には、$|a| &lt; r &lt; 1$ となる $r$ を選びます。極限の定義から、ある番号 $N$ が存在し、$n \ge N$ ならば $|u_{n+1}/u_n| &lt; r$ となることを利用します。&lt;/li&gt;
  &lt;li&gt;この不等式を繰り返し使うと、$|u_n|$ が公比 $r$ の等比数列 $C \cdot r^n$ で抑えられることがわかります。&lt;/li&gt;
  &lt;li&gt;$0 &lt; r &lt; 1$ なので $\lim_{n \to \infty} r^n = 0$ です。&lt;/li&gt;
  &lt;li&gt;はさみうちの原理を使って $\lim_{n \to \infty} |u_n| = 0$ を導き、そこから $\lim_{n \to \infty} u_n = 0$ を示します。&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;解答&lt;/h2&gt;
&lt;p&gt;　$\lim_{n \to \infty} |u_{n+1}/u_n| = |a|$ であり、仮定より $|a| &lt; 1$ です。&lt;/p&gt;
&lt;p&gt;　ここで、$|a| &lt; r &lt; 1$ を満たす実数 $r$ を1つ選びます。（例えば $r = (|a| + 1) / 2$ とすればよいです。）&lt;/p&gt;
&lt;p&gt;　$\epsilon = r - |a|$ とおくと、$\epsilon &gt; 0$ です。
数列の極限の定義から、この $\epsilon$ に対して、ある自然数 $N$ が存在し、$n \ge N$ を満たすすべての $n$ について、
$$
| |u_{n+1}/u_n| - |a| | &lt; \epsilon
$$
が成り立ちます。この不等式は、
$$
|u_{n+1}/u_n| - |a| &lt; \epsilon \iff |u_{n+1}/u_n| &lt; |a| + \epsilon = |a| + (r - |a|) = r
$$
を意味します。つまり、$n \ge N$ のとき $|u_{n+1}/u_n| &lt; r$ が成り立ちます。&lt;/p&gt;
&lt;p&gt;　$n &gt; N$ のとき、この関係を繰り返し用いると、
$$
\begin{aligned}
|u_n| &amp;= \left| \frac{u_n}{u_{n-1}} \cdot \frac{u_{n-1}}{u_{n-2}} \cdot \dots \cdot \frac{u_{N+1}}{u_N} \cdot u_N \right| \\
&amp;= \left|\frac{u_n}{u_{n-1}}\right| \cdot \left|\frac{u_{n-1}}{u_{n-2}}\right| \cdot \dots \cdot \left|\frac{u_{N+1}}{u_N}\right| \cdot |u_N| \\
&amp;&lt; r \cdot r \cdot \dots \cdot r \cdot |u_N| = r^{n-N} |u_N|
\end{aligned}
$$
となります。ここで $C = |u_N| / r^N$ とおくと、$C$ は正の定数であり、$|u_n| &lt; C \cdot r^n$ と書けます。&lt;/p&gt;
&lt;p&gt;　したがって、$n &gt; N$ において $0 \le |u_n| &lt; C \cdot r^n$ が成り立ちます。
$0 &lt; r &lt; 1$ なので $\lim_{n \to \infty} r^n = 0$ であり、よって $\lim_{n \to \infty} C \cdot r^n = 0$ です。&lt;/p&gt;
&lt;p&gt;　はさみうちの原理より、$\lim_{n \to \infty} |u_n| = 0$ が得られます。
$-|u_n| \le u_n \le |u_n|$ であり、$\lim_{n \to \infty} |u_n| = 0$ かつ $\lim_{n \to \infty} -|u_n| = 0$ なので、再びはさみうちの原理より $\lim_{n \to \infty} u_n = 0$ となります。&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/4342116927514439527/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2025/07/p71-62.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/4342116927514439527'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/4342116927514439527'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2025/07/p71-62.html' title='P71 問62 （マグロウヒル大学演習シリーズ 微積分(上)）を解く．'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>日本</georss:featurename><georss:point>36.204824 138.252924</georss:point><georss:box>7.8945901638211566 103.09667400000001 64.51505783617884 173.409174</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-5540011318407040390</id><published>2025-07-25T08:40:00.001+09:00</published><updated>2025-07-25T08:40:12.127+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="マグロウヒル大学演習シリーズ 微積分(上)"/><title type='text'>P71 問66 （マグロウヒル大学演習シリーズ 微積分(上)）を解く．</title><content type='html'>&lt;div style=&quot;border: 1px solid #ccc; border-radius: 8px; padding: 16px; margin-bottom: 16px;&quot;&gt;
  &lt;h3 style=&quot;margin-top: 0; border-bottom: 1px solid #eee; padding-bottom: 8px;&quot;&gt;問66&lt;/h3&gt;
  &lt;p&gt;　$\{ u_n \}$がフィボナッチ数列ならば，$\lim_{n \to \infty} \frac{u_{n+1}}{u_n} = \frac{1 + \sqrt{5}}{2}$ であることを証明せよ．&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;　フィボナッチ数列 $\{ u_n \}$ は $u_1=1, u_2=1, u_{n+2} = u_{n+1} + u_n ( n \ge 1 )$で定義されます．この問題の主張は，フィボナッチ数列のある項とその次の項の比が黄金比に収束するということです．等比数列ならばその比は一定だが，フィボナッチ数列はだんだんと黄金比になります．&lt;/p&gt;

&lt;h2&gt;証明の方針&lt;/h2&gt;
&lt;p&gt;　本問題の目標は，$u_{n+1}/u_n$ の極限が黄金比に等しいことを示すことです．すなわち，&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;$a_n = u_{n+1}/u_n$ とおいたとき，$a_n$ が収束すること．
    &lt;ul&gt;
      &lt;li&gt;部分列の単調性・有界性から，収束性を示します．&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;$a_n$ の極限は黄金比であること．
    &lt;ul&gt;
      &lt;li&gt;部分列の極限から，$a_n$の極限を特定します．&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;を示すことと同じです．&lt;/p&gt;

&lt;h2&gt;解答&lt;/h2&gt;
&lt;p&gt;　$a_n = u_{n+1}/u_n$ とおく．$a_n$ が単調増加もしくは単調減少で有界ならば収束するので，単調性を調べるために $a_{n+1} - a_n$ について考えたいが，うまく単調性を見い出せません．$a_1,a_2,a_3,...$ を計算してみると，振動しているようなので，部分列（偶数番目・奇数番目）の単調性からアプローチします．部分列がともに同じ値に収束すれば，数列もその値に収束するからです．&lt;/p&gt;

&lt;h3&gt;1. 部分列の単調性を示す．&lt;/h3&gt;
&lt;p&gt;　$a_n$ は振動しているので，以下で偶数番目と奇数番目の部分列の単調性を示します．&lt;/p&gt;

&lt;h5 style=&quot;font-weight: bold; margin-top: 1.5em;&quot;&gt;偶数番目の部分列 $a_{2k}$ の単調減少性を示す．&lt;/h5&gt;
&lt;p&gt;　偶数番目の部分列 $a_{2k}$ が単調減少であること、つまり $a_{2k+2} - a_{2k} &lt; 0$ が成り立つことを示します。&lt;/p&gt;
$$
\begin{aligned}
a_{2k+2} - a_{2k} &amp;= \frac{u_{2k+3}}{u_{2k+2}} - \frac{u_{2k+1}}{u_{2k}} \\
                  &amp;= \frac{u_{2k+3} u_{2k} - u_{2k+1} u_{2k+2}}{u_{2k+2} u_{2k}}
\end{aligned}
$$
&lt;p&gt;ここで、分子 $u_{2k+3} u_{2k} - u_{2k+1} u_{2k+2}$ に着目し，フィボナッチ数列の漸化式 $u_n = u_{n-1} + u_{n-2}$ を用いて変形します．&lt;/p&gt;
$$
\begin{aligned}
u_{2k+3} u_{2k} - u_{2k+1} u_{2k+2} &amp;= (u_{2k+2} + u_{2k+1}) u_{2k} - u_{2k+1} u_{2k+2} \\
  &amp;= u_{2k+2} u_{2k} + u_{2k+1} u_{2k} - u_{2k+1} u_{2k+2} \\
  &amp;= u_{2k+2} u_{2k} - u_{2k+1} (u_{2k+2} - u_{2k}) \\
  &amp;= u_{2k+2} u_{2k} - u_{2k+1}^2
\end{aligned}
$$
&lt;p&gt;ここで&lt;a href=&quot;/other/0301_cassini_identity/&quot;&gt;カッシーニの恒等式&lt;/a&gt;を適用します．これはフィボナッチ数列の重要な性質です．&lt;/p&gt;
&lt;div style=&quot;border: 1px solid #ccc; border-radius: 8px; padding: 16px; margin-top: 1em; margin-bottom: 1em; background-color: #f9f9f9;&quot;&gt;
  &lt;h4 style=&quot;margin-top: 0; border-bottom: 1px solid #eee; padding-bottom: 8px;&quot;&gt;カッシーニの恒等式&lt;/h4&gt;
  $$u_{n+2} u_n - u_{n+1}^2 = (-1)^{n+1}$$
&lt;/div&gt;
&lt;p&gt;すると $u_{2k+2} u_{2k} - u_{2k+1}^2 = (-1)^{2k+1}$ なので，&lt;/p&gt;
$$
\begin{aligned}
a_{2k+2} - a_{2k} &amp;= \frac{(-1)^{2k+1}}{u_{2k+2} u_{2k}} \\
                  &amp;= \frac{-1}{u_{2k+2} u_{2k}} &lt; 0
\end{aligned}
$$
&lt;p&gt;となり，すなわち $a_{2k+2} - a_{2k} &lt; 0$ なので，$a_{2k}$ の単調減少性が示されました．&lt;/p&gt;

&lt;h5 style=&quot;font-weight: bold; margin-top: 1.5em;&quot;&gt;奇数番目の部分列 $a_{2k-1}$ の単調増加性を示す．&lt;/h5&gt;
&lt;p&gt;　奇数番目の部分列 $a_{2k-1}$ が単調増加であること、つまり $a_{2k+1} - a_{2k-1} &gt; 0$ が成り立つことを示します。偶数番目の部分列と同様にすると，&lt;/p&gt;
$$
a_{2k+1} - a_{2k-1} = \frac{1}{u_{2k+1} u_{2k-1}} &gt; 0
$$
&lt;p&gt;となり，すなわち $a_{2k+1} - a_{2k-1} &gt; 0$ なので，$a_{2k-1}$ の単調増加性が示されました．&lt;/p&gt;

&lt;h3&gt;2. 部分列の有界性を示す．&lt;/h3&gt;

&lt;h5 style=&quot;font-weight: bold; margin-top: 1.5em;&quot;&gt;偶数番目の部分列の有界性を示す．&lt;/h5&gt;
&lt;p&gt;　偶数番目の部分列 $a_{2k} = u_{2k+1} / u_{2k}$ は、すでに&lt;strong&gt;単調減少&lt;/strong&gt;であることを示しました．したがって、この数列は最初の項 $a_2$ が最大値となります。$a_2 = u_3 / u_2 = 2 / 1 = 2$．ゆえに、$a_{2k} \le 2$ が常に成り立ちます。&lt;/p&gt;
&lt;p&gt;　次に、この数列が下に有界であることを示します。ここで数列$a_n$は以下の関係式が成り立つことを使います．&lt;/p&gt;
$$
a_{n+1} - a_n = \frac{(-1)^{n+1}}{u_{n+1} u_n}
$$
&lt;p&gt;数列 $a_n$ の定義とカッシーニの恒等式から導くことができます．$(-1)^{n+1}$ の符号がポイントです．&lt;/p&gt;
&lt;p&gt;$n$ が偶数の場合，つまり $n = 2k$ とすると，&lt;/p&gt;
$$
a_{2k+1} - a_{2k} = \frac{-1}{u_{2k+1} u_{2k}} &lt; 0
$$
&lt;p&gt;となり，$a_{2k+1} &lt; a_{2k}$ が成り立ちます．これは、&lt;strong&gt;奇数番目の項は、直前の偶数番目の項より小さい&lt;/strong&gt;ことを意味します。（例: $a_3 &lt; a_2, a_5 &lt; a_4$ ）&lt;/p&gt;
&lt;p&gt;$n$ が奇数の場合，つまり $n = 2k - 1$ とすると，&lt;/p&gt;
$$
a_{2k} - a_{2k-1} = \frac{1}{u_{2k} u_{2k-1}} &gt; 0
$$
&lt;p&gt;となり，$a_{2k} &gt; a_{2k-1}$が成り立ちます．これは、&lt;strong&gt;偶数番目の項は、直前の奇数番目の項より大きい&lt;/strong&gt;ことを意味します。（例: $a_2 &gt; a_1, a_4 &gt; a_3$ ）&lt;/p&gt;
&lt;p&gt;　これら2つの結果をまとめると，&lt;strong&gt;偶数番目の数列の項は前後の奇数番目の項より大きい&lt;/strong&gt;ということです．そして，奇数番目の部分列が単調増加で $1 \le a_{2k-1}$ であることを合わせると，$1 \le a_{2k-1} &lt; a_{2k} \le 2$ なので，$1 &lt; a_{2k} \le 2$ です．つまり，&lt;strong&gt;偶数番目の部分列は有界である&lt;/strong&gt;ことが示せました．&lt;/p&gt;

&lt;h5 style=&quot;font-weight: bold; margin-top: 1.5em;&quot;&gt;奇数番目の部分列の有界性を示す．&lt;/h5&gt;
&lt;p&gt;　偶数番目の部分列の有界性を示す中で，$1 \le a_{2k-1} &lt; a_{2k} \le 2$ が明らかになりました．これはつまり，$1 \le a_{2k-1} &lt; 2$ なので，奇数番目の部分列の有界性も示せました．&lt;/p&gt;

&lt;h3&gt;3. 極限を示す．&lt;/h3&gt;
&lt;p&gt;　偶数番目の部分列 $a_{2k}$ と 奇数番目の部分列 $a_{2k-1}$ はともに単調な数列で有界であることがわかりました．したがって，それぞれ収束します．そこで，$\lim_{k \to \infty} a_{2k} = L_e, \lim_{k \to \infty} a_{2k-1} = L_o$ とします．&lt;/p&gt;

&lt;h5 style=&quot;font-weight: bold; margin-top: 1.5em;&quot;&gt;極限が同一であること．&lt;/h5&gt;
&lt;p&gt;　数列 $a_n$ は以下の関係を満たすことが計算するとわかります．&lt;/p&gt;
$$
a_{n+1} = 1 + \frac{1}{a_n}
$$
&lt;p&gt;つまり，&lt;/p&gt;
$$
\begin{aligned}
a_{2k+1} &amp;= 1 + \frac{1}{a_{2k}} \\
a_{2k} &amp;= 1 + \frac{1}{a_{2k-1}}
\end{aligned}
$$
&lt;p&gt;となり，両辺，極限を取ると&lt;/p&gt;
$$
\begin{aligned}
L_o &amp;= 1 + \frac{1}{L_e} \\
L_e &amp;= 1 + \frac{1}{L_o}
\end{aligned}
$$
&lt;p&gt;となります．この連立方程式を解くと $L_o = L_e$ となります．極限が同じであることがわかりました．&lt;/p&gt;

&lt;h5 style=&quot;font-weight: bold; margin-top: 1.5em;&quot;&gt;極限を特定する．&lt;/h5&gt;
&lt;p&gt;　上の連立方程式から，共通の極限値を $L$ とすると&lt;/p&gt;
$$
L = 1 + \frac{1}{L}
$$
&lt;p&gt;が成り立っており，これを $L$ について解くと，$L$が正であることから，&lt;/p&gt;
$$
L = \frac{1 + \sqrt{5}}{2}
$$
&lt;p&gt;となります．&lt;/p&gt;

&lt;p style=&quot;margin-top: 1.5em;&quot;&gt;　以上より，$ \lim_{n \to \infty} \frac{u_{n+1}}{u_n} = \frac{1 + \sqrt{5}}{2}$ が示せました．&lt;/p&gt;



</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/5540011318407040390/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2025/07/p71-66.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/5540011318407040390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/5540011318407040390'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2025/07/p71-66.html' title='P71 問66 （マグロウヒル大学演習シリーズ 微積分(上)）を解く．'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>日本</georss:featurename><georss:point>36.204824 138.252924</georss:point><georss:box>7.8945901638211566 103.09667400000001 64.51505783617884 173.409174</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-6561969972551559660</id><published>2025-07-24T15:49:00.003+09:00</published><updated>2025-07-25T08:53:01.505+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="マグロウヒル大学演習シリーズ 微積分(上)"/><title type='text'>P71 問65 （マグロウヒル大学演習シリーズ 微積分(上)）を解く．</title><content type='html'>&lt;div style=&quot;border: 1px solid #ccc; border-radius: 8px; padding: 16px; margin-bottom: 16px;&quot;&gt;
&lt;h2&gt;問65&lt;/h2&gt;
&lt;p&gt;
 $$
  \lim_{n \to \infty} n \sin(1/n) = 1 を証明せよ。
 $$
&lt;/p&gt;
&lt;/div&gt;
&lt;hr/&gt;
&lt;p&gt;　$ n \sin(1/n)$ の極限が $1$ であることを証明します。この証明では、関数の極限の基本的な性質と、幾何学的な考察に基づいて、はさみうちの原理で解きます。&lt;/p&gt;

&lt;h2&gt;関数の極限&lt;/h2&gt;
&lt;p&gt;求めたい極限は $\lim_{n \to \infty} n \sin(1/n)$ です。&lt;/p&gt;
&lt;p&gt;ここで、$x = 1/n$ とおきます。$n \to \infty$ のとき、$x \to 0$ となります。特に、$n$ は自然数なので、$x$ は正の値を取りながら $0$ に近づきます（$x \to 0^+$）。&lt;/p&gt;
&lt;p&gt;したがって、与えられた数列の極限は、関数の極限として次のように書き換えられます。&lt;/p&gt;
$$ \lim_{n \to \infty} n \sin(1/n) = \lim_{x \to 0^+} \frac{1}{x} \sin(x) $$
&lt;p&gt;これは次のように変形できます。&lt;/p&gt;
$$ \lim_{x \to 0^+} \frac{\sin(x)}{x} $$



&lt;h2&gt;幾何学的な考察とはさみうちの原理&lt;/h2&gt;
&lt;p&gt;この極限 $\lim_{x \to 0^+} \frac{\sin(x)}{x}$ が $1$ に等しいことを、幾何学的な考察とはさみうちの原理を用いて証明します。&lt;/p&gt;
&lt;p&gt;$0 &lt; x &lt; \pi/2$ の範囲を考えます。単位円（半径 $1$ の円）において、中心を $O$、円周上の点を $A, B$ とします。点 $A=(1,0)$ とし、角 $AOB$ を $x$ ラジアンとします。また、点 $A$ から $x$ 軸に垂直に伸ばした線と、線分 $OB$ の延長線との交点を $C$ とします。&lt;/p&gt;
&lt;p&gt;このとき、図形的に以下の面積の大小関係が成り立ちます。&lt;/p&gt;
&lt;p&gt;三角形 $OAB$ の面積 $\le$ 扇形 $OAB$ の面積 $\le$ 三角形 $OAC$ の面積&lt;/p&gt;
&lt;p&gt;それぞれの面積を計算すると：&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;&lt;b&gt;三角形 $OAB$ の面積:&lt;/b&gt; 底辺 $1$、高さ $\sin x$ なので、$\frac{1}{2} \cdot 1 \cdot \sin x = \frac{1}{2} \sin x$&lt;/li&gt;
    &lt;li&gt;&lt;b&gt;扇形 $OAB$ の面積:&lt;/b&gt; 半径 $1$、中心角 $x$ なので、$\frac{1}{2} \cdot 1^2 \cdot x = \frac{1}{2} x$&lt;/li&gt;
    &lt;li&gt;&lt;b&gt;三角形 $OAC$ の面積:&lt;/b&gt; 底辺 $OA=1$、高さ $AC=\tan x$ なので、$\frac{1}{2} \cdot 1 \cdot \tan x = \frac{1}{2} \tan x$&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;これらの面積の大小関係を式で表すと、&lt;/p&gt;
$$ \frac{1}{2} \sin x \le \frac{1}{2} x \le \frac{1}{2} \tan x $$
&lt;p&gt;この不等式全体を $2$ 倍すると、&lt;/p&gt;
$$ \sin x \le x \le \tan x $$
&lt;p&gt;となります。&lt;/p&gt;
&lt;p&gt;ここで、$0 &lt; x &lt; \pi/2$ では $\sin x &gt; 0$ なので、この不等式全体を $\sin x$ で割ることができます。不等号の向きは変わりません。&lt;/p&gt;
$$ \frac{\sin x}{\sin x} \le \frac{x}{\sin x} \le \frac{\tan x}{\sin x} $$
$$ 1 \le \frac{x}{\sin x} \le \frac{\sin x / \cos x}{\sin x} $$
$$ 1 \le \frac{x}{\sin x} \le \frac{1}{\cos x} $$
&lt;p&gt;次に、各辺の逆数を取ります。逆数を取ると不等号の向きが逆転することに注意してください。&lt;/p&gt;
$$ \frac{1}{1} \ge \frac{\sin x}{x} \ge \cos x $$
&lt;p&gt;整理すると、&lt;/p&gt;
$$ \cos x \le \frac{\sin x}{x} \le 1 $$
&lt;p&gt;となります。&lt;/p&gt;
&lt;p&gt;ここで、$x \to 0^+$ の極限を考えます。&lt;/p&gt;
$$ \lim_{x \to 0^+} \cos x = \cos 0 = 1 $$
&lt;p&gt;したがって、はさみうちの原理により、&lt;/p&gt;
$$ \lim_{x \to 0^+} \frac{\sin x}{x} = 1 $$
&lt;p&gt;が導かれます。&lt;/p&gt;


&lt;h2&gt;結論&lt;/h2&gt;
&lt;p&gt;この結果を元の数列の極限に戻すと、&lt;/p&gt;
$$ \lim_{n \to \infty} n \sin(1/n) = \lim_{x \to 0^+} \frac{\sin(x)}{x} = 1 $$
&lt;p&gt;したがって、$ n \sin(1/n)$ の極限は $1$ であることが証明されました。&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/6561969972551559660/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2025/07/p71-65.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/6561969972551559660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/6561969972551559660'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2025/07/p71-65.html' title='P71 問65 （マグロウヒル大学演習シリーズ 微積分(上)）を解く．'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>日本</georss:featurename><georss:point>36.204824 138.252924</georss:point><georss:box>7.8945901638211566 103.09667400000001 64.51505783617884 173.409174</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-759652207823303819</id><published>2025-07-23T16:10:00.003+09:00</published><updated>2025-07-25T08:54:54.599+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="マグロウヒル大学演習シリーズ 微積分(上)"/><title type='text'>P72 問67 （マグロウヒル大学演習シリーズ 微積分(上)）を解く．</title><content type='html'>&lt;h2 style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; color: #333;&quot;&gt;数列 $\left(1 + \frac{1}{n}\right)^{n+1}$ の単調性と極限&lt;/h2&gt;

&lt;div style=&quot;border: 1px solid #ccc; border-radius: 8px; padding: 16px; margin-bottom: 16px;&quot;&gt;
  &lt;h3 style=&quot;margin-top: 0; border-bottom: 1px solid #eee; padding-bottom: 8px;&quot;&gt;問67&lt;/h3&gt;
&lt;p&gt;
$$u_n = \left(1 + \frac{1}{n}\right)^{n+1} n=1,2,3, \cdots $$
が単調減少数列であること、そしてその極限が $e$ であることを証明せよ．
&lt;/p&gt;
&lt;/div&gt;

&lt;h3 style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; color: #555;&quot;&gt;1. 単調減少性の証明&lt;/h3&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
数列 $u_n$ が単調減少であることを示すには、$u_{n+1} \le u_n$ が全ての $n \ge 1$ について成り立つことを証明すれば良いです。これは、比 $\frac{u_{n+1}}{u_n} \le 1$ を示すことと同義です。
&lt;/p&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
まず、$u_n$ と $u_{n+1}$ の定義を書き出しましょう。
$$u_n = \left(1 + \frac{1}{n}\right)^{n+1} = \left(\frac{n+1}{n}\right)^{n+1}$$
$$u_{n+1} = \left(1 + \frac{1}{n+1}\right)^{n+2} = \left(\frac{n+2}{n+1}\right)^{n+2}$$
&lt;/p&gt;


&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
次に、$\frac{u_{n+1}}{u_n} \le 1$ が示すべき不等式、すなわち $u_{n+1} \le u_n$ を直接見ていきましょう。
$$\left(1 + \frac{1}{n+1}\right)^{n+2} \le \left(1 + \frac{1}{n}\right)^{n+1}$$
&lt;/p&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
この不等式を変形してみます。
$$\frac{\left(1 + \frac{1}{n+1}\right)^{n+2}}{\left(1 + \frac{1}{n}\right)^{n+1}} \le 1$$
$$ \left(1 + \frac{1}{n+1}\right) \left( \frac{1 + \frac{1}{n+1}}{1 + \frac{1}{n}} \right)^{n+1} \le 1 $$
ここで、分数部分を計算します。
$$ \frac{1 + \frac{1}{n+1}}{1 + \frac{1}{n}} = \frac{\frac{n+2}{n+1}}{\frac{n+1}{n}} = \frac{n+2}{n+1} \cdot \frac{n}{n+1} = \frac{n(n+2)}{(n+1)^2} = \frac{n^2+2n}{n^2+2n+1} $$
よって、示すべき不等式は以下のようになります。
$$ \left(\frac{n+2}{n+1}\right) \left(\frac{n^2+2n}{n^2+2n+1}\right)^{n+1} \le 1 $$
&lt;/p&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
上記で得られた不等式をさらに変形し、以下の形を考えます。
$$ \frac{n+2}{n+1} \le \left(\frac{n^2+2n+1}{n^2+2n}\right)^{n+1} $$
$$ \frac{n+2}{n+1} \le \left(1 + \frac{1}{n^2+2n}\right)^{n+1} $$
&lt;/p&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
ここで、次の一般的な不等式を利用します。
任意の正の数 $x \neq 0$ と実数 $r&gt;1$ に対して、$(1+x)^r &gt; 1+rx$ が成り立ちます。（これはベルヌーイの不等式です．）
$X = \frac{1}{n^2+2n}$、$R = n+1$ と置くと、$x &gt; 0$、$r &gt; 1$ です。
したがって、
$$
  \begin{align*}
  \left(1 + \frac{1}{n^2+2n}\right)^{n+1} &amp;&gt; 1 + (n+1) \cdot \frac{1}{n^2+2n} \\
     &amp;= 1 + \frac{n+1}{n(n+2)} \\
     &amp;= \frac{n(n+2) + (n+1)}{n(n+2)} \\
     &amp;= \frac{n^2+2n+n+1}{n^2+2n} \\
     &amp;= \frac{n^2+3n+1}{n^2+2n} 
  \end{align*}
$$
&lt;/p&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
これで、示したい不等式は次のようになります。
$$ \frac{n+2}{n+1} \le \frac{n^2+3n+1}{n^2+2n} $$
この不等式が真であることを確認します。両辺に分母を掛けて整理します。（分母は全て正なので不等号の向きは変わりません。）
$$ (n+2)(n^2+2n) \le (n+1)(n^2+3n+1) $$
左辺を展開します。
$$ n^3 + 2n^2 + 2n^2 + 4n = n^3 + 4n^2 + 4n $$
右辺を展開します。
$$ n^3 + 3n^2 + n + n^2 + 3n + 1 = n^3 + 4n^2 + 4n + 1 $$
したがって、元の不等式は次のようになります。
$$ n^3 + 4n^2 + 4n \le n^3 + 4n^2 + 4n + 1 $$
この不等式は、$0 \le 1$ となり、明らかに全ての $n \ge 1$ に対して真です。
&lt;/p&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
よって、我々が目指していた
$$ \left(\frac{n+2}{n+1}\right) \left(\frac{n^2+2n}{n^2+2n+1}\right)^{n+1} \le 1 $$
すなわち $\frac{u_{n+1}}{u_n} \le 1$ が証明されました。これは $u_{n+1} \le u_n$ を意味し、数列 $u_n$ は単調減少であることを示しています。
（$n \ge 1$ においては常に厳密な不等号 $u_{n+1} &lt; u_n$ が成り立ちます。）
&lt;/p&gt;

&lt;h3 style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; color: #555;&quot;&gt;2. 極限値の計算&lt;/h3&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
次に、数列 $u_n$ の極限値を求めます。
$$\lim_{n \to \infty} u_n = \lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^{n+1}$$
この式は次のように変形できます。
$$\lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^{n+1} = \lim_{n \to \infty} \left[ \left(1 + \frac{1}{n}\right)^n \cdot \left(1 + \frac{1}{n}\right)^1 \right]$$
&lt;/p&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
極限の性質を利用して、積の極限として分離します。
$$= \left( \lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n \right) \cdot \left( \lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^1 \right)$$
&lt;/p&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
ここで、自然対数の底 $e$ の定義から、$\lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n = e$ です。
また、2番目の極限は容易に計算できます。
$$\lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^1 = (1 + 0) = 1$$
&lt;/p&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
したがって、
$$\lim_{n \to \infty} u_n = e \cdot 1 = e$$
&lt;/p&gt;

&lt;p style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6;&quot;&gt;
数列 $u_n = \left(1 + \frac{1}{n}\right)^{n+1}$ は単調減少であり、その極限値は $e$ であることが証明されました。
&lt;/p&gt;

</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/759652207823303819/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2025/07/p72-67.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/759652207823303819'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/759652207823303819'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2025/07/p72-67.html' title='P72 問67 （マグロウヒル大学演習シリーズ 微積分(上)）を解く．'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>日本</georss:featurename><georss:point>36.204824 138.252924</georss:point><georss:box>7.8945901638211566 103.09667400000001 64.51505783617884 173.409174</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-79764320201371705</id><published>2025-07-22T10:23:00.003+09:00</published><updated>2025-07-25T08:55:44.402+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="マグロウヒル大学演習シリーズ 微積分(上)"/><title type='text'>P72 問68 （マグロウヒル大学演習シリーズ 微積分(上)）を解く．</title><content type='html'>&lt;div style=&quot;border: 1px solid #ccc; border-radius: 8px; padding: 16px; margin-bottom: 16px;&quot;&gt;
  &lt;h3 style=&quot;margin-top: 0; border-bottom: 1px solid #eee; padding-bottom: 8px;&quot;&gt;問68&lt;/h3&gt;
&lt;p&gt;　すべての $n&gt;=N$ について $a_n \ge b_n$ であり、かつ $\lim_{n \to \infty} a_n = A$ および $\lim_{n \to \infty} b_n = B$ が成り立つならば、$A \ge B$ である。&lt;/p&gt;
&lt;/div&gt;

&lt;h3&gt;解答の方針&lt;/h3&gt;

&lt;p&gt;この証明は、&lt;strong&gt;「$A-B \ge 0$ を示す」&lt;/strong&gt;という方針で進めます。&lt;/p&gt;


&lt;h3&gt;証明&lt;/h3&gt;

&lt;p&gt;まず、$c_n$ という新しい数列を次のように定義します。&lt;/p&gt;

$$c_n = a_n - b_n$$

&lt;p&gt;与えられた条件は以下の3つです。&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt;すべての $n&gt;=N$ に対して $a_n \ge b_n$&lt;/li&gt;
    &lt;li&gt;$\lim_{n \to \infty} a_n = A$&lt;/li&gt;
    &lt;li&gt;$\lim_{n \to \infty} b_n = B$&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;条件1に着目すると、$a_n \ge b_n$ であるため、両辺から $b_n$ を引くと、$a_n - b_n \ge 0$ となります。&lt;br&gt;
これは、私たちが定義した数列 $c_n$ が常に非負であることを意味します。&lt;/p&gt;

&lt;p&gt;つまり、&lt;strong&gt;すべての $n&gt;=N$ に対して $c_n \ge 0$&lt;/strong&gt; が成り立ちます。&lt;/p&gt;

&lt;p&gt;次に、この数列 $c_n$ の極限を調べてみましょう。&lt;br&gt;
極限の線形性（和と差の極限はそれぞれの極限の和と差になる性質）を利用します。&lt;/p&gt;

$$\lim_{n \to \infty} c_n = \lim_{n \to \infty} (a_n - b_n)$$

&lt;p&gt;与えられた条件2と3を適用すると、以下のようになります。&lt;/p&gt;

$$\lim_{n \to \infty} (a_n - b_n) = \lim_{n \to \infty} a_n - \lim_{n \to \infty} b_n$$

&lt;p&gt;したがって、&lt;/p&gt;

$$\lim_{n \to \infty} c_n = A - B$$

&lt;p&gt;ここで、重要な定理を思い出しましょう。&lt;br&gt;
&lt;strong&gt;「もし数列 $c_n$ がすべての項で $c_n \ge 0$ であり、かつその極限が存在して $L$ であるならば、その極限 $L$ もまた $L \ge 0$ である」&lt;/strong&gt;という定理です。&lt;/p&gt;

&lt;p&gt;私たちの数列 $c_n$ は、すべての $n$ で $c_n \ge 0$ であり、その極限は $A - B$ です。&lt;br&gt;
この定理を適用すると、次が成り立たなければなりません。&lt;/p&gt;

$$A - B \ge 0$$

&lt;p&gt;この不等式の両辺に $B$ を加えることで、最終的な結論が得られます。&lt;/p&gt;

$$A \ge B$$

&lt;hr&gt;

&lt;h3&gt;まとめ&lt;/h3&gt;

&lt;p&gt;この証明により、もし2つの数列が常に片方がもう片方以上であるという関係を保ちながら収束するならば、それぞれの極限値の間にも同じ大小関係が成り立つことが示されました。これは、極限操作が不等式関係を保存する良い例であり、解析学において非常に基本的な性質の一つです。&lt;/p&gt;

&lt;p&gt;この内容が、皆さんの数学の理解に役立てば幸いです。&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/79764320201371705/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2025/07/p72-68.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/79764320201371705'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/79764320201371705'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2025/07/p72-68.html' title='P72 問68 （マグロウヒル大学演習シリーズ 微積分(上)）を解く．'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>日本</georss:featurename><georss:point>36.204824 138.252924</georss:point><georss:box>7.8945901638211566 103.09667400000001 64.51505783617884 173.409174</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-8929583697391495667</id><published>2021-10-03T18:47:00.000+09:00</published><updated>2021-10-03T18:47:46.501+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="moto"/><category scheme="http://www.blogger.com/atom/ns#" term="pytest"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>【moto】motoでtransact_write_itemsをモックする。【Python】</title><content type='html'>&lt;h2&gt;motoでtransact_write_itemsをモックする。&lt;/h2&gt;
&lt;p&gt;moto と transact_write_items で検索すると、motoを拡張してモックする方法が上位に表示される。詳しく調べていないが、moto  2.2.4 では拡張せずともモックできるので、サンプルを提示したい。&lt;/p&gt;
&lt;p&gt;この記事ではテストコードは一部だけ記載するので、完全なものは https://github.com/tomohikoseven/moto_transact_write_items を参照ください。&lt;/p&gt;

&lt;h2&gt;実装コード&lt;/h2&gt;
&lt;p&gt;実装したコードは、ClickCountというテーブルにItemをトランザクションで追加・更新（アトミックカウンタ）するものです。DynamoDBをご存知の方には、簡単なものかと思います。&lt;/p&gt;
&lt;p&gt;簡単に説明すると、以下の実装コードはハッシュキー：month は文字列 YYYYMM を、レンジキー（ソートキー）：date は文字列 YYYYMMDD を期待して、1トランザクションで2つのItemに対し、clickCountをカウントUPするものになります。&lt;/p&gt;
&lt;p&gt;トランザクションの1つ目は日付の末尾が00となっており、月間のclickCountをカウントUPします。今回の記事では気にすることではないです。&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;
(index.py)
import boto3


client = boto3.client(&#39;dynamodb&#39;,  region_name=&#39;ap-northeast-1&#39;)
def lambda_handler( month:str, date:str ):
  try:
    response = client.transact_write_items(
      TransactItems=[
        {
          &#39;Update&#39; : {
            &#39;Key&#39; : {
              &#39;hKey&#39;: { &#39;S&#39;: month },
              &#39;rKey&#39;: { &#39;S&#39;: month + &#39;00&#39; }
            },
            &#39;TableName&#39;:&#39;ClickCount&#39;,
            &#39;UpdateExpression&#39;: &#39;ADD clickCount :increment&#39;,
            &#39;ExpressionAttributeValues&#39; : {
              &#39;:increment&#39;: { &#39;N&#39;: &#39;1&#39; }
            }
          }
        },
        {
          &#39;Update&#39; : {
            &#39;Key&#39; : {
              &#39;hKey&#39;: { &#39;S&#39;: month },
              &#39;rKey&#39;: { &#39;S&#39;: date }
            },
            &#39;TableName&#39;:&#39;ClickCount&#39;,
            &#39;UpdateExpression&#39;: &#39;ADD clickCount :increment&#39;,
            &#39;ExpressionAttributeValues&#39; : {
              &#39;:increment&#39;: { &#39;N&#39;: &#39;1&#39; }
            }
          }
        }
      ]
    )
  except Exception as e :
    print(&quot;===&quot;)
    print(e)
    raise e

  return 200
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;テストコード&lt;/h2&gt;
&lt;p&gt;pytestでテストコードを実行します。&lt;/p&gt;
&lt;p&gt;motoでモックするテストコードを記述したことがある方は難しいことはないです。mock_dynamodb2をimportして、アノテーション@mock_dynamodb2をテストケースに付けてやればよいです。&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;
(test_index.py)

# 本当のテストは1ケースだけではないので、ここでは余分なライブラリがインポートされています。
from importlib import import_module
import boto3
from moto import mock_dynamodb2
from unittest import mock
from botocore.exceptions import ClientError
import pytest


@mock_dynamodb2
def test_success(set_dynamodb_Count):
  # mock dynamodb
  table = set_dynamodb_Count()

  month = &#39;202101&#39;
  date = &#39;20210101&#39;
  from src.index import lambda_handler
  res = lambda_handler( month, date )

  item = table.get_item(Key={&#39;hKey&#39;:month, &#39;rKey&#39;: date})
  assert res == 200
  assert item[&#39;Item&#39;][&#39;clickCount&#39;] == 1

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;conftest.pyに set_dynamodb_Count を記載しています。テストにはこちらも必要になります。test_index.pyと同一フォルダに置いてください。&lt;/p&gt;

&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;
(conftest.py)
import pytest
import boto3

@pytest.fixture
def set_dynamodb_Count():
  def definition():
    dynamodb = boto3.resource(&#39;dynamodb&#39;, region_name=&#39;ap-northeast-1&#39;)
    dynamodb.create_table(
      TableName=&#39;ClickCount&#39;,
      KeySchema=[
          {
              &#39;AttributeName&#39;: &#39;hKey&#39;,
              &#39;KeyType&#39;: &#39;HASH&#39;
          },
          {
              &#39;AttributeName&#39;: &#39;rKey&#39;,
              &#39;KeyType&#39;: &#39;RANGE&#39;
          }
      ],
      AttributeDefinitions=[
          {
              &#39;AttributeName&#39;: &#39;hKey&#39;,
              &#39;AttributeType&#39;: &#39;S&#39;
          },
          {
              &#39;AttributeName&#39;: &#39;rKey&#39;,
              &#39;AttributeType&#39;: &#39;S&#39;
          }
      ],
    )

    return dynamodb.Table(&#39;ClickCount&#39;)
  return definition
&lt;/code&gt;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/8929583697391495667/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/10/motomototransactwriteitemspython.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/8929583697391495667'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/8929583697391495667'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/10/motomototransactwriteitemspython.html' title='【moto】motoでtransact_write_itemsをモックする。【Python】'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-4749390975607240223</id><published>2021-08-11T19:40:00.004+09:00</published><updated>2021-08-11T19:40:56.773+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTML"/><title type='text'>【HTML】過去入力したメールアドレスのサジェスト表示の方法</title><content type='html'>&lt;p&gt;&amp;lt;input id=&quot;email&quot; type=&quot;email&quot; /&amp;gt;&lt;/p&gt;&lt;p&gt;id=&quot;email&quot; を付けないと、フィールドにフォーカスを当てたときにサジェスト表示されない。&lt;/p&gt;&lt;p&gt;passwordだと、パスワード保存設定（Chrome系のブラウザの設定）だったり、iCloudキーチェーンの有効化設定＋パスワード自動入力設定を有効化しなければならないが、メールアドレスに関してはその必要がないみたい。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/4749390975607240223/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/08/html.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/4749390975607240223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/4749390975607240223'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/08/html.html' title='【HTML】過去入力したメールアドレスのサジェスト表示の方法'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-6014775666398826552</id><published>2021-08-11T19:26:00.003+09:00</published><updated>2021-08-11T19:26:24.028+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>【正規表現】連続する同一文字を含む文字列かどうかを判断する。【JavaScript】</title><content type='html'>&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;
var continueChar = function( str ) {
  const regexp = /(.)\1{3,}/;   // 4つ連続で同一文字を含む
  return regexp.test( str );
};

exports.continueChar = continueChar;
&lt;/code&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/6014775666398826552/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/08/javascript.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/6014775666398826552'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/6014775666398826552'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/08/javascript.html' title='【正規表現】連続する同一文字を含む文字列かどうかを判断する。【JavaScript】'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-2980921758391997217</id><published>2021-07-21T06:53:00.005+09:00</published><updated>2021-07-21T07:45:42.903+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="FIRE"/><title type='text'>【FIRE前】2021年7月の支出</title><content type='html'>&lt;p&gt;夫婦2人＋猫1匹の支出&lt;/p&gt;

&lt;table border=&quot;1&quot; bordercolor=&quot;#888&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse; border-color: rgb(136, 136, 136); border-width: 1px; margin: 15px;&quot;&gt;
  &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;項目&lt;/th&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;支出額&lt;/th&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;備考&lt;/th&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;家賃&lt;/td&gt;&lt;td&gt;7.5万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;食費&lt;/td&gt;&lt;td&gt;4.8万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;電気・ガス・水道&lt;/td&gt;&lt;td&gt;0.0万円&lt;/td&gt;&lt;td&gt;給与日が早く、支払い前なので、0万円。&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;日用品&lt;/td&gt;&lt;td&gt;0.3万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;服&lt;/td&gt;&lt;td&gt;0.4万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;整髪&lt;/td&gt;&lt;td&gt;0.0万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;医療&lt;/td&gt;&lt;td&gt;0.0万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;通信費&lt;/td&gt;&lt;td&gt;0.7万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;お小遣い&lt;/td&gt;&lt;td&gt;1.9万円&lt;/td&gt;&lt;td&gt;夫婦二人分&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;寄付&lt;/td&gt;&lt;td&gt;0.28万円&lt;/td&gt;&lt;td&gt;子供食堂へ寄付。&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;生命保険料&lt;/td&gt;&lt;td&gt;0.2万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;その他&lt;/td&gt;&lt;td&gt;0.6万円&lt;/td&gt;&lt;td&gt;書籍代とか。&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;合計&lt;/td&gt;&lt;td&gt;16.68万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;下記書籍をベースとして、早期リタイアを目指しています。&lt;/p&gt;
&lt;iframe frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;amp;t=tomohikoseven-22&amp;amp;m=amazon&amp;amp;o=9&amp;amp;p=8&amp;amp;l=as1&amp;amp;IS2=1&amp;amp;detail=1&amp;amp;asins=B0832P1VPX&amp;amp;linkId=2bd61e21fe6fce92c848ada512c1f399&amp;amp;bc1=ffffff&amp;amp;lt1=_blank&amp;amp;fc1=333333&amp;amp;lc1=0066c0&amp;amp;bg1=ffffff&amp;amp;f=ifr&quot; style=&quot;height: 240px; width: 120px;&quot;&gt;
    &lt;/iframe&gt;
&lt;iframe frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;amp;t=tomohikoseven-22&amp;amp;m=amazon&amp;amp;o=9&amp;amp;p=8&amp;amp;l=as1&amp;amp;IS2=1&amp;amp;detail=1&amp;amp;asins=4478108579&amp;amp;linkId=f694e8e4213fd730796ebacd1a4ec239&amp;amp;bc1=ffffff&amp;amp;lt1=_blank&amp;amp;fc1=333333&amp;amp;lc1=0066c0&amp;amp;bg1=ffffff&amp;amp;f=ifr&quot; style=&quot;height: 240px; width: 120px;&quot;&gt;
    &lt;/iframe&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/2980921758391997217/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/07/fire20217.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/2980921758391997217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/2980921758391997217'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/07/fire20217.html' title='【FIRE前】2021年7月の支出'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-1183294099531225177</id><published>2021-07-02T08:17:00.000+09:00</published><updated>2021-07-02T08:17:03.034+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="FIRE"/><title type='text'>【FIRE前】FIRE後の国民年金の支払いをどうするか。</title><content type='html'>&lt;p&gt;&amp;nbsp;夫婦2人＋猫1匹で生活をしています（FIRE前）。&lt;/p&gt;&lt;p&gt;FIREした後、支出の中でなかなかの割合を占めるものがあります。&lt;span style=&quot;background-color: white;&quot;&gt;&lt;u&gt;国民年金&lt;/u&gt;&lt;/span&gt;です。&lt;/p&gt;



一人あたり約1.6万円なので、夫婦であれば年間約38.4万円の支出です。&lt;div&gt;&lt;br /&gt;&lt;div&gt;未来のための投資と考えれば、まあよいかなと思う反面、米国ETF買っていた方がよいのでは？とも思います。（最終的には米国インデックスETFの方がお金がよりもらえます。）&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;結論から言えば、国民年金は全納もしくは免除（全額、4分の3、半額、4分の1）で&lt;u&gt;&lt;b&gt;未納期間を作らない&lt;/b&gt;&lt;/u&gt;ようにしたいです。&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;
その訳は、&lt;b&gt;障害年金をもらうための保険&lt;/b&gt;としてです。&lt;/div&gt;&lt;div&gt;ずっと健康ではなく、障害を負ってしまうかもしれないので、そのための対策です。&lt;/div&gt;&lt;div&gt;障害年金をもらうための納付要件は以下です。（&lt;a href=&quot;https://www.syougainenkin-shien.com/requirement&quot; target=&quot;_blank&quot;&gt;引用元&lt;/a&gt;）&lt;br /&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;
保険料納付要件の原則は加入期間の３分の２以上納めていること。&lt;/li&gt;&lt;li&gt;1.を満たさない場合は、直近１年間に滞納期間がないこと。&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;例えば40歳でFIRE（完全リタイア）し、国民年金を納めない場合、50歳まではよいとして、それ以降に障害を負ってしまうと加入期間が３分の２未満となり、障害年金がもらえません。障害となってしまってしかもお金がもらえないとなると、二重の痛手です。&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;よって、FIRE前の現在の結論としては&lt;b&gt;未納期間を作らない&lt;/b&gt;ようにします。&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;p&gt;下記書籍をベースとして、早期リタイアを目指しています。&lt;/p&gt;
&lt;iframe frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;amp;t=tomohikoseven-22&amp;amp;m=amazon&amp;amp;o=9&amp;amp;p=8&amp;amp;l=as1&amp;amp;IS2=1&amp;amp;detail=1&amp;amp;asins=B0832P1VPX&amp;amp;linkId=2bd61e21fe6fce92c848ada512c1f399&amp;amp;bc1=ffffff&amp;amp;lt1=_blank&amp;amp;fc1=333333&amp;amp;lc1=0066c0&amp;amp;bg1=ffffff&amp;amp;f=ifr&quot; style=&quot;height: 240px; width: 120px;&quot;&gt;
    &lt;/iframe&gt;
&lt;iframe frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;amp;t=tomohikoseven-22&amp;amp;m=amazon&amp;amp;o=9&amp;amp;p=8&amp;amp;l=as1&amp;amp;IS2=1&amp;amp;detail=1&amp;amp;asins=4478108579&amp;amp;linkId=f694e8e4213fd730796ebacd1a4ec239&amp;amp;bc1=ffffff&amp;amp;lt1=_blank&amp;amp;fc1=333333&amp;amp;lc1=0066c0&amp;amp;bg1=ffffff&amp;amp;f=ifr&quot; style=&quot;height: 240px; width: 120px;&quot;&gt;
    &lt;/iframe&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/1183294099531225177/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/07/firefire.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/1183294099531225177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/1183294099531225177'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/07/firefire.html' title='【FIRE前】FIRE後の国民年金の支払いをどうするか。'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-4758985578372851016</id><published>2021-06-28T20:24:00.002+09:00</published><updated>2021-06-29T13:48:10.767+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="FIRE"/><title type='text'>【FIRE前】何をポイントにお金が貯まっていったのか。</title><content type='html'>&lt;div&gt;長期的にFIREを目指していたわけではないのですが、7年くらい共働きで働くうちに、貯金が貯まっていきました。この期間は、夫婦2人の生活において以下の決まり事を守っていました。&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;家は買わない。買うとしても老後に現金一括で購入。&lt;/li&gt;&lt;li&gt;保険は最低限の保証のもののみ。一人1000円／月程度のもの。&lt;/li&gt;&lt;li&gt;車は買わない。&lt;/li&gt;&lt;li&gt;結婚式は挙げない。写真のみ。&lt;/li&gt;&lt;li&gt;所得が低い方（私）を生活費とする。&lt;/li&gt;&lt;li&gt;急な支出は生活費以外から。&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;結果的に、借金をしない・固定費を抑えるような生活になったのかもしれません。&lt;/div&gt;&lt;/div&gt;&lt;div&gt;ただ、&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;新婚旅行はハワイへ&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;この一度だけは大きな出費をしました。&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;これからFIREをする上で、今より1万円くらい安い賃貸物件（月6万円ほど）に引っ越すつもりです。&lt;/div&gt;

&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;p&gt;下記書籍をベースとして、早期リタイアを目指しています。&lt;/p&gt;
&lt;iframe style=&quot;width:120px;height:240px;&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;t=tomohikoseven-22&amp;m=amazon&amp;o=9&amp;p=8&amp;l=as1&amp;IS2=1&amp;detail=1&amp;asins=B0832P1VPX&amp;linkId=2bd61e21fe6fce92c848ada512c1f399&amp;bc1=ffffff&amp;amp;lt1=_blank&amp;fc1=333333&amp;lc1=0066c0&amp;bg1=ffffff&amp;f=ifr&quot;&gt;
    &lt;/iframe&gt;
&lt;iframe frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;amp;t=tomohikoseven-22&amp;amp;m=amazon&amp;amp;o=9&amp;amp;p=8&amp;amp;l=as1&amp;amp;IS2=1&amp;amp;detail=1&amp;amp;asins=4478108579&amp;amp;linkId=f694e8e4213fd730796ebacd1a4ec239&amp;amp;bc1=ffffff&amp;amp;lt1=_blank&amp;amp;fc1=333333&amp;amp;lc1=0066c0&amp;amp;bg1=ffffff&amp;amp;f=ifr&quot; style=&quot;height: 240px; width: 120px;&quot;&gt;
    &lt;/iframe&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/4758985578372851016/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/06/fire_28.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/4758985578372851016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/4758985578372851016'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/06/fire_28.html' title='【FIRE前】何をポイントにお金が貯まっていったのか。'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-3484093118173931169</id><published>2021-06-27T21:07:00.007+09:00</published><updated>2021-07-16T08:12:22.045+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="FIRE"/><title type='text'>【FIRE前】FIRE時の金融資産目標はどうするか。</title><content type='html'>&lt;p&gt;&amp;nbsp;4%ルールの&lt;a href=&quot;https://www.aaii.com/files/pdf/6794_retirement-savings-choosing-a-withdrawal-rate-that-is-sustainable.pdf&quot; target=&quot;_blank&quot;&gt;原論&lt;/a&gt;によれば、株式：75%、債券：25％の割合が成功確率が一番いいわけですが、株式：100%と現金（生活費2年分）でFIREしようとしてます。&lt;/p&gt;&lt;p&gt;別の&lt;a href=&quot;https://earlyretirementnow.com/2016/12/07/the-ultimate-guide-to-safe-withdrawal-rates-part-1-intro/&quot; target=&quot;_blank&quot;&gt;サイト&lt;/a&gt;によると、4%ルールをより長期間に適用した結果は、株式100%の方が高確率で成功します。（以下の画像を参照。）&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgPyW0Iq6oeW8qqYG-j-Jpy8rmcD5iKz3oYf4lS93nd-FNZBTnfroWRSqCewP8D0f40_UKsP6Sg58suY9ioJSl_4ptG88m9k_lI080MoVa58Iucv2hBCuS4Ux6CcQKDeYRg0MNhstGHzE/s764/swr-part1-table1.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;500&quot; data-original-width=&quot;764&quot; height=&quot;391&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgPyW0Iq6oeW8qqYG-j-Jpy8rmcD5iKz3oYf4lS93nd-FNZBTnfroWRSqCewP8D0f40_UKsP6Sg58suY9ioJSl_4ptG88m9k_lI080MoVa58Iucv2hBCuS4Ux6CcQKDeYRg0MNhstGHzE/w598-h391/swr-part1-table1.png&quot; width=&quot;598&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
（引用：&lt;a href=&quot;https://earlyretirementnow.com/2016/12/07/the-ultimate-guide-to-safe-withdrawal-rates-part-1-intro/&quot; target=&quot;_blank&quot;&gt;Early Retirement Now&lt;/a&gt;）
&lt;p&gt;つまり、&lt;u&gt;&lt;b&gt;株式100％でFIREしようとしています&lt;/b&gt;&lt;/u&gt;。&lt;/p&gt;
【FIRE時の目標資産】
&lt;table border=&quot;1&quot; bordercolor=&quot;#888&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse; border-color: rgb(136, 136, 136); border-width: 1px; margin: 15px;&quot;&gt;
  &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;項目&lt;/th&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;目標額&lt;/th&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;備考&lt;/th&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;VOO&lt;/td&gt;&lt;td&gt;6000万円&lt;/td&gt;&lt;td&gt;楽天証券では、手数料無料で購入可能。&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;現金&lt;/td&gt;&lt;td&gt;600万円ほど&lt;/td&gt;&lt;td&gt;株式市場が暴落した際に生活費を下ろす。2年分程度。&lt;/td&gt;&lt;/tr&gt; 
  &lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;なぜ、VOOかというとバンガード社の人気米国株ETFの中で、インデックスで成績がよいものだったためです。2020/07現在、VOOの目標額の83%を達成しています。&lt;/p&gt;

VOO以外の株（個別株、米国ETF）を新型コロナによる株式市場暴落時に仕込んでいましたので、それらを売却してVOOに付け替えていきたいと思います。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;下記書籍をベースとして、早期リタイアを目指しています。&lt;/p&gt;
&lt;iframe frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;amp;t=tomohikoseven-22&amp;amp;m=amazon&amp;amp;o=9&amp;amp;p=8&amp;amp;l=as1&amp;amp;IS2=1&amp;amp;detail=1&amp;amp;asins=B0832P1VPX&amp;amp;linkId=2bd61e21fe6fce92c848ada512c1f399&amp;amp;bc1=ffffff&amp;amp;lt1=_blank&amp;amp;fc1=333333&amp;amp;lc1=0066c0&amp;amp;bg1=ffffff&amp;amp;f=ifr&quot; style=&quot;height: 240px; width: 120px;&quot;&gt;
    &lt;/iframe&gt;
&lt;iframe frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;amp;t=tomohikoseven-22&amp;amp;m=amazon&amp;amp;o=9&amp;amp;p=8&amp;amp;l=as1&amp;amp;IS2=1&amp;amp;detail=1&amp;amp;asins=4478108579&amp;amp;linkId=f694e8e4213fd730796ebacd1a4ec239&amp;amp;bc1=ffffff&amp;amp;lt1=_blank&amp;amp;fc1=333333&amp;amp;lc1=0066c0&amp;amp;bg1=ffffff&amp;amp;f=ifr&quot; style=&quot;height: 240px; width: 120px;&quot;&gt;
    &lt;/iframe&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/3484093118173931169/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/06/firefire_27.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/3484093118173931169'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/3484093118173931169'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/06/firefire_27.html' title='【FIRE前】FIRE時の金融資産目標はどうするか。'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgPyW0Iq6oeW8qqYG-j-Jpy8rmcD5iKz3oYf4lS93nd-FNZBTnfroWRSqCewP8D0f40_UKsP6Sg58suY9ioJSl_4ptG88m9k_lI080MoVa58Iucv2hBCuS4Ux6CcQKDeYRg0MNhstGHzE/s72-w598-h391-c/swr-part1-table1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-3169586811594457503</id><published>2021-06-26T21:35:00.006+09:00</published><updated>2021-06-29T13:47:10.204+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="FIRE"/><title type='text'>【FIRE前】2021年6月の支出</title><content type='html'>&lt;p&gt;夫婦2人＋猫1匹の6月の支出&lt;/p&gt;

&lt;table border=&quot;1&quot; bordercolor=&quot;#888&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse; border-color: rgb(136, 136, 136); border-width: 1px; margin: 15px;&quot;&gt;
  &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;項目&lt;/th&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;支出額&lt;/th&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;備考&lt;/th&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;家賃&lt;/td&gt;&lt;td&gt;7.5万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;食費&lt;/td&gt;&lt;td&gt;4.7万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;電気・ガス・水道&lt;/td&gt;&lt;td&gt;0.6万円&lt;/td&gt;&lt;td&gt;水道代は含まず。&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;日用品&lt;/td&gt;&lt;td&gt;0.65万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;服&lt;/td&gt;&lt;td&gt;0.4万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;整髪&lt;/td&gt;&lt;td&gt;0.1万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;医療&lt;/td&gt;&lt;td&gt;0.38万円&lt;/td&gt;&lt;td&gt;歯医者代&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;通信費&lt;/td&gt;&lt;td&gt;1.16万円&lt;/td&gt;&lt;td&gt;契約事務手数料5000円含む。後で戻ってくる。&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;お小遣い&lt;/td&gt;&lt;td&gt;1.5万円&lt;/td&gt;&lt;td&gt;夫婦二人分&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;寄付&lt;/td&gt;&lt;td&gt;0.28万円&lt;/td&gt;&lt;td&gt;子供食堂へ寄付。&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;生命保険料&lt;/td&gt;&lt;td&gt;0.2万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;交通費&lt;/td&gt;&lt;td&gt;0.15万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;その他&lt;/td&gt;&lt;td&gt;0.1万円&lt;/td&gt;&lt;td&gt;書籍代とか。&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;合計&lt;/td&gt;&lt;td&gt;17.72万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;下記書籍をベースとして、早期リタイアを目指しています。&lt;/p&gt;
&lt;iframe style=&quot;width:120px;height:240px;&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;t=tomohikoseven-22&amp;m=amazon&amp;o=9&amp;p=8&amp;l=as1&amp;IS2=1&amp;detail=1&amp;asins=B0832P1VPX&amp;linkId=2bd61e21fe6fce92c848ada512c1f399&amp;bc1=ffffff&amp;amp;lt1=_blank&amp;fc1=333333&amp;lc1=0066c0&amp;bg1=ffffff&amp;f=ifr&quot;&gt;
    &lt;/iframe&gt;
&lt;iframe frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;amp;t=tomohikoseven-22&amp;amp;m=amazon&amp;amp;o=9&amp;amp;p=8&amp;amp;l=as1&amp;amp;IS2=1&amp;amp;detail=1&amp;amp;asins=4478108579&amp;amp;linkId=f694e8e4213fd730796ebacd1a4ec239&amp;amp;bc1=ffffff&amp;amp;lt1=_blank&amp;amp;fc1=333333&amp;amp;lc1=0066c0&amp;amp;bg1=ffffff&amp;amp;f=ifr&quot; style=&quot;height: 240px; width: 120px;&quot;&gt;
    &lt;/iframe&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/3169586811594457503/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/06/fire20216.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/3169586811594457503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/3169586811594457503'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/06/fire20216.html' title='【FIRE前】2021年6月の支出'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-3509708897489799529</id><published>2021-06-26T21:11:00.001+09:00</published><updated>2021-06-26T21:35:35.395+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="FIRE"/><title type='text'>【FIRE前】朝食、昼食、夕食は何を食べているか。</title><content type='html'>&lt;p&gt;&amp;nbsp;FIRE前ですが、お弁当や総菜ではなく、自炊をするように心掛けています。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;【朝食】フルグラ＋コーンフレーク＋オートミール（インスタント）＋豆乳（低脂肪）。&lt;/p&gt;&lt;p&gt;【昼食】野菜＋豚肉たっぷりの味噌汁のみ。&lt;/p&gt;&lt;p&gt;【夕食】野菜＋豚肉たっぷりの炒め物。もしくは麺類（袋ラーメン、そうめんなど）。&lt;/p&gt;&lt;p&gt;だいたいこのようなもの。炒め物の場合、ご飯を付けたりもします。&lt;/p&gt;&lt;p&gt;食費はだいたい楽天Edyで払うのですが、マネーフォワードで見ると月4万円使っていました。おー、使っているな。&lt;/p&gt;
&lt;p&gt;フルグラ&lt;/p&gt;
&lt;iframe style=&quot;width:120px;height:240px;&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;t=tomohikoseven-22&amp;m=amazon&amp;o=9&amp;p=8&amp;l=as1&amp;IS2=1&amp;detail=1&amp;asins=B00YBYCWAC&amp;linkId=90fbf31b251162f2fb5f62d3585e01ca&amp;bc1=ffffff&amp;amp;lt1=_blank&amp;fc1=333333&amp;lc1=0066c0&amp;bg1=ffffff&amp;f=ifr&quot;&gt;
    &lt;/iframe&gt;
&lt;p&gt;オートミール（インスタント）&lt;/p&gt;
&lt;iframe style=&quot;width:120px;height:240px;&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&amp;t=tomohikoseven-22&amp;m=amazon&amp;o=9&amp;p=8&amp;l=as1&amp;IS2=1&amp;detail=1&amp;asins=B07HHDVHZV&amp;linkId=7814131a326cdba6ea78e8e7b0c00291&amp;bc1=ffffff&amp;amp;lt1=_blank&amp;fc1=333333&amp;lc1=0066c0&amp;bg1=ffffff&amp;f=ifr&quot;&gt;
    &lt;/iframe&gt;

</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/3509708897489799529/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/06/fire.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/3509708897489799529'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/3509708897489799529'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/06/fire.html' title='【FIRE前】朝食、昼食、夕食は何を食べているか。'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-1913485810470295933</id><published>2021-06-22T19:27:00.003+09:00</published><updated>2021-06-26T21:35:50.618+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="FIRE"/><title type='text'>【FIRE前】FIRE時の年間支出目標</title><content type='html'>&lt;p&gt;&amp;nbsp;夫婦2人（子供なし、猫1匹）４０代でのFIRE時の年間支出目標&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;table border=&quot;1&quot; bordercolor=&quot;#888&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse; border-color: rgb(136, 136, 136); border-width: 1px; margin: 15px;&quot;&gt;
  &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;項目&lt;/th&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;目標額&lt;/th&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;備考&lt;/th&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;家賃&lt;/td&gt;&lt;td&gt;80万円&lt;/td&gt;&lt;td&gt;月6万円、更新料、火災保険を含む&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;食費&lt;/td&gt;&lt;td&gt;36万円&lt;/td&gt;&lt;td&gt;月3万円&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;電気・ガス・水道&lt;/td&gt;&lt;td&gt;14.4万円&lt;/td&gt;&lt;td&gt;月1.2万円&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;日用品&lt;/td&gt;&lt;td&gt;4.8万円&lt;/td&gt;&lt;td&gt;月0.4万円&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;服&lt;/td&gt;&lt;td&gt;4.8万円&lt;/td&gt;&lt;td&gt;月0.4万円&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;整髪&lt;/td&gt;&lt;td&gt;2.4万円&lt;/td&gt;&lt;td&gt;月0.2万円&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;医療&lt;/td&gt;&lt;td&gt;4.8万円&lt;/td&gt;&lt;td&gt;月0.2万円&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;通信費&lt;/td&gt;&lt;td&gt;12万円&lt;/td&gt;&lt;td&gt;携帯：0.5万円／二人、インターネット：0.5万円&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;交通費&lt;/td&gt;&lt;td&gt;7万円&lt;/td&gt;&lt;td&gt;主に帰省代&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;お小遣い&lt;/td&gt;&lt;td&gt;24万円&lt;/td&gt;&lt;td&gt;月1万円／一人&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;国民健康保険&lt;/td&gt;&lt;td&gt;4万円&lt;/td&gt;&lt;td&gt;減免7割適用を仮定。&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;所得税・住民税&lt;/td&gt;&lt;td&gt;0万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;国民年金&lt;/td&gt;&lt;td&gt;0～39.8万円&lt;/td&gt;&lt;td&gt;約1.6万円／月／一人。余裕がないときは延納。&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;合計&lt;/td&gt;&lt;td&gt;204～234万円&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;


  
    
  &lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/1913485810470295933/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/06/firefire.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/1913485810470295933'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/1913485810470295933'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/06/firefire.html' title='【FIRE前】FIRE時の年間支出目標'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-582925990724296032</id><published>2021-05-30T10:45:00.002+09:00</published><updated>2021-05-30T10:45:58.440+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Day.js"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>【JavaScript】Day.jsでの日付妥当性をisValid()で。</title><content type='html'>&lt;!-- wp:paragraph --&gt;
&lt;p&gt;Day.jsで日付の妥当性は isValid() を使うとできます。しかし、検索をすると使えない（日付の検証には使えない。）と結果が出てきます。それは誤りで、plugin を利用すれば可能です。customParseFormat を追加しましょう。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;ポイント&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:list --&gt;
&lt;ul&gt;&lt;li&gt;プラグイン &lt;span class=&quot;marker-under&quot;&gt;customParseFormat&lt;/span&gt; を追加。&lt;/li&gt;&lt;li&gt;dayjs() の&lt;span class=&quot;marker-under&quot;&gt;第3&lt;/span&gt;&lt;span class=&quot;marker-under&quot;&gt;引数 strict に true&lt;/span&gt; を指定。&lt;/li&gt;&lt;/ul&gt;
&lt;!-- /wp:list --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);

// プラグイン 追加
const customParseFormat = require(&#39;dayjs/plugin/customParseFormat&#39;);
dayjs.extend(customParseFormat);

console.log( dayjs( &#39;20210102&#39;, &#39;YYYYMMDD&#39; ).isValid() ); // =&amp;gt; true
console.log( dayjs( &#39;20210132&#39;, &#39;YYYYMMDD&#39; ).isValid() ); // =&amp;gt; true
console.log( dayjs( &#39;20210102&#39;, &#39;YYYYMMDD&#39;, true ).isValid() ); // =&amp;gt; true
console.log( dayjs( &#39;20210132&#39;, &#39;YYYYMMDD&#39;, true ).isValid() ); // =&amp;gt; false
console.log( dayjs( &#39;2021013a&#39;, &#39;YYYYMMDD&#39;, true ).isValid() ); // =&amp;gt; false&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/582925990724296032/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/05/javascriptdayjsisvalid.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/582925990724296032'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/582925990724296032'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/05/javascriptdayjsisvalid.html' title='【JavaScript】Day.jsでの日付妥当性をisValid()で。'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-7883969948279208627</id><published>2021-05-30T10:44:00.001+09:00</published><updated>2021-05-30T10:44:31.169+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Day.js"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="Parse"/><title type='text'>【JavaScript】Day.jsのAPIサンプル（Parse編）</title><content type='html'>&lt;!-- wp:paragraph --&gt;
&lt;p&gt; 　Day.jsの使い方を知るためにサンプルを作っています。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;Parse&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　日付や時刻を含む文字列や数値からオブジェクトを作成するものです。作成されたオブジェクトはUTC時間だったりするので、利用時は気を付けないと想定とずれた時間になります。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;Parse&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　テキストをオブジェクトに変換します。日本語の日付を使うなどする場合など、「Invalid Date」でエラーとなってしまうときは、&lt;span class=&quot;marker-under&quot;&gt;CustomParseFormat プラグインを利用する&lt;/span&gt;ことも頭に入れておくとよいです。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);

// JST:2021-04-30 00:00:00
// UTC:2021-04-29 15:00:00 (日本との差は-9時間のため)
console.log( dayjs(&#39;2021-04-30&#39;, &#39;YYYY-MM-DD&#39;).toDate() );
// =&amp;gt; 2021-04-29T15:00:00.000Z (UTC)
console.log( dayjs(&#39;2021年04月30日&#39;, &#39;YYYY年MM月DD日&#39;).toDate() );
// =&amp;gt; Invalid Date (日本語があるとパースできない.)

// プラグインを追加 
const CustomParseFormat = require(&#39;dayjs/plugin/customParseFormat&#39;);
dayjs.extend(CustomParseFormat);

console.log( dayjs(&#39;2021年04月30日&#39;, &#39;YYYY年MM月DD日&#39;).toDate() );
// =&amp;gt; 2021-04-29T15:00:00.000Z (日本語があってもパースできる.)
console.log( dayjs(&#39;2021年04月30日&#39;, &#39;YYYY年MM月DD日&#39;).locale(&#39;ja&#39;).format() );
// =&amp;gt; 2021-04-30T00:00:00+09:00 (日本でロケールしてみただけ.)&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;Now&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt; 　&lt;span class=&quot;marker-under&quot;&gt;現在時刻のオブジェクト&lt;/span&gt;&lt;span class=&quot;marker-under&quot;&gt;を&lt;/span&gt;&lt;span class=&quot;marker-under&quot;&gt;取得&lt;/span&gt;します。日本時間にするには &lt;span class=&quot;marker-under&quot;&gt;ロケール変換+format()&lt;/span&gt; します。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);

let now_utc = dayjs();
let now_jst = dayjs().locale(&#39;ja&#39;);
console.log( now_utc.toDate() );
// =&amp;gt; 2021-04-30T00:09:31.085Z (こちらは0時)
console.log( now_jst.format() );
// =&amp;gt; 2021-04-30T09:09:31+09:00 (こちらは9時. toDate() はUTCになってしまうので注意.)&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;String&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　&lt;a href=&quot;https://ja.wikipedia.org/wiki/ISO_8601&quot;&gt;ISO 8601&lt;/a&gt;形式の&lt;span class=&quot;marker-under&quot;&gt;文字列からオブジェクトを作成&lt;/span&gt;します。日付と時刻の間に&quot;T&quot;を付け、時刻の後ろに&quot;Z&quot;や&quot;+0900&quot;などを付与した文字列です。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);

let utc = dayjs(&#39;2021-04-15T15:00:00.000Z&#39;);
console.log( utc.toDate() );

let jst = dayjs(&#39;2021-04-15T15:00:00.000+0900&#39;);
console.log( jst.locale(&#39;ja&#39;).format() ); // toDate()はUTC時間で出力される&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;String + Format&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　事前に日付のフォーマットわかっていれば、引数の日付の文字列からオブジェクトが作成できます。注意すべきは &lt;span class=&quot;marker-under&quot;&gt;CustomParseFormat プラグインを使わなければいけない&lt;/span&gt;ことです。補足ですが、dayjs()の第4引数に真偽を指定すると、結果が変わります。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);
// プラグイン
const customParseFormat = require(&#39;dayjs/plugin/customParseFormat&#39;);

dayjs.extend(customParseFormat); // プラグイン追加
let jst = dayjs(&#39;2021年10月18日&#39;, &#39;YYYY年MM月DD日&#39;, &#39;ja&#39;);
console.log(jst.locale(&#39;ja&#39;).format());

let jst_imp = dayjs(&#39;2021年10月32日&#39;, &#39;YYYY年MM月DD日&#39;, &#39;ja&#39;);
let jst_strict = dayjs(&#39;2021年10月32日&#39;, &#39;YYYY年MM月DD日&#39;, &#39;ja&#39;, true);

console.log(jst_imp.locale(&#39;ja&#39;).format());
// =&amp;gt; 2021-11-01T00:00:00+09:00  第4引数がtrueでない場合、日付の繰り越しが起こる.
console.log(jst_strict.locale(&#39;ja&#39;).format());
// =&amp;gt; Invalid Date 第4引数がtrueの場合、日付の厳密性がチェックされ、存在しない日付の場合、
エラー(Invalid Date)になる.&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　日付のフォーマットが１つではなく複数指定される可能性がある場合でもオブジェクト作成できます。日付のフォーマットを配列で指定してあげます。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);
const customParseFormat = require(&#39;dayjs/plugin/customParseFormat&#39;);

dayjs.extend(customParseFormat);
let date  = dayjs(&quot;2001-12-25&quot;, &amp;#91;&quot;YYYY&quot;, &quot;YYYY-MM-DD&quot;], &#39;ja&#39;, true);
let date2 = dayjs(&quot;2001&quot;, &amp;#91;&quot;YYYY&quot;, &quot;YYYY-MM-DD&quot;], &#39;ja&#39;, true);
console.log(date.locale(&#39;ja&#39;).format());  // =&amp;gt; 2001-12-25T00:00:00+09:00
console.log(date2.locale(&#39;ja&#39;).format()); // =&amp;gt; 2001-01-01T00:00:00+09:00


let date3 = dayjs(&quot;2001-25-12&quot;, &amp;#91;&quot;YYYY&quot;, &quot;YYYY-MM-DD&quot;], &#39;ja&#39;, true);
let date4 = dayjs(&quot;2001-25-12&quot;, &amp;#91;&quot;YYYY&quot;, &quot;YYYY-MM-DD&quot;], &#39;ja&#39;);
console.log(date3.locale(&#39;ja&#39;).format());  // =&amp;gt; Invalid Date
console.log(date4.locale(&#39;ja&#39;).format());  // =&amp;gt; 2001-01-01T00:00:00+09:00&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;Unix Timestamp (milliseconds)&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　ミリ秒を表す数値を指定することでオブジェクトを作成します。基準日は1970年1月1日午前0時です。引数に指定したミリ秒だけ加算された日時のオブジェクトが作成されます。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);

let date = dayjs(0);
console.log( date.toDate() );
// =&amp;gt; 1970-01-01T00:00:00.000Z

let date1 = dayjs(1);
console.log( date1.toDate() );
// =&amp;gt; 1970-01-01T00:00:00.001Z&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;Unix Timestamp (seconds)&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt; 　秒を表す数値を指定し、オブジェクトを作成します。基準日は1970年1月1日午前0時です。引数に指定した秒だけ加算された日時のオブジェクトが作成されます。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);

let date = dayjs.unix(0);
console.log( date.toDate() );
// =&amp;gt; 1970-01-01T00:00:00.000Z

let date2 = dayjs.unix(1);
console.log( date2.toDate() );
// =&amp;gt; 1970-01-01T00:00:01.000Z dayjs()をラップしている.

let date3 = dayjs( 1 * 1000 );
console.log( date3.toDate() );
// =&amp;gt; 1970-01-01T00:00:01.000Z &lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;Date&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　JavaScriptのDateオブジェクトからオブジェクトを作成します。Dateオブジェクトのクローンを返すため、元のDateオブジェクトを変更しても、Day.jsオブジェクトは変更されません。その逆も同様です。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);

var d = new Date(2019, 7, 18); // monthは0-11を指定し、1月-12月を扱う罠.
var day = dayjs(d);

console.log( d );  // =&amp;gt; 2019-08-17T15:00:00.000Z
console.log( day.toDate() );  // =&amp;gt; 2019-08-17T15:00:00.000&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;Object&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　オブジェクトからDay.jsオブジェクトを作成します。ObjectSupport プラグインを追加して使用します。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);
const ObjectSupport = require(&#39;dayjs/plugin/objectSupport&#39;); // プラグイン

// プラグイン追加.
dayjs.extend(ObjectSupport);

let now = dayjs();
let date = dayjs({ hour:15, minute:10 });
console.log( now.toDate() );
// =&amp;gt; 2021-05-01T07:51:36.994Z
console.log( date.toDate() );
// =&amp;gt; 2021-05-01T06:10:00.000Z
// 当日の日本時間15時10分を指す?。UTCにすると9時間前なので、6時10分となる。

now = dayjs();
let date2 = dayjs({});  // 空のオブジェクトは現在日時
console.log( now.toDate() );
// =&amp;gt; 2021-05-01T07:54:59.148Z
console.log( date2.toDate() );
// =&amp;gt; 2021-05-01T07:54:59.148Z

let date3 = dayjs({ year :2010, month :3, day :5, hour :15, minute :10, second :3, millisecond :123});
console.log( date3.toDate() );
// =&amp;gt; 2010-04-05T06:10:03.123Z
// monthは0-11の整数で、1月-12月を表す.&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;Array&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　配列からDay.jsオブジェクトを作成します。arraySupport プラグインを追加する必要があります。dayjs([]) は現在時刻です。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);
const ArraySupport = require(&#39;dayjs/plugin/arraySupport&#39;);

dayjs.extend(ArraySupport);

// &amp;#91; 年、月、日、時、分、秒、ミリ秒 ]
let date = dayjs(&amp;#91;2010, 1, 14, 15, 25, 50, 125]);
console.log( date.toDate() );
// =&amp;gt; 2010-02-14T06:25:50.125Z
// month部分は0-11を指定することで、1月-12月を表します。
// ログ出力ではUTC時間になるため、時刻が9時間前となります。 

let date2 = dayjs(&amp;#91;2010, 6]);     // July 1st
console.log( date2.toDate() );
// =&amp;gt; 2010-06-30T15:00:00.000Z
// month:6 は7月のこと。7/1 00:00:00から-9時間となり、6/30 15:00:00となる。 
// UTC時間は面倒だ。&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;UTC&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　UTC時間のDay.jsオブジェクトを作成します。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);
const utc = require(&#39;dayjs/plugin/utc&#39;);

dayjs.extend(utc);

let date = dayjs();
console.log( date.format() );
// =&amp;gt; 2021-05-02T09:10:25+09:00
// 日本で実行しているので、format()は日本時間が出力される。
let date_utc = dayjs().utc();
console.log( date_utc.format() );
// =&amp;gt; 2021-05-02T00:10:25Z
// 日本で実行していても、format()はUTC時間で出力される。 &lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;Dayjs Clone&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　Day.jsオブジェクトを複製して、同じオブジェクトを作成します。2種類の方法があり、複製元からclone()を使うか、dayjs()の引数に複製元を渡すかです。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);

let a = dayjs();
let b = a.clone();

console.log( a.toDate() ); // =&amp;gt; 2021-05-02T00:18:31.274Z
console.log( b.toDate() ); // =&amp;gt; 2021-05-02T00:18:31.274Z

a = dayjs();
b = dayjs(a);

console.log( a.toDate() ); // =&amp;gt; 2021-05-02T00:18:31.325Z
console.log( b.toDate() ); // =&amp;gt; 2021-05-02T00:18:31.325Z&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;Validation&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　日付が正しいかチェックします。customParseFormat プラグインを使用します。注意しなければならないのは、dayjs()の第3引数の真偽です。厳密に日付の正しさを求めるならば true を指定します。そうでない場合、日付が正しくない場合でも繰り上げなどの計算をしてくれます。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;const dayjs = require(&#39;dayjs&#39;);
// プラグイン
const customParseFormat = require(&#39;dayjs/plugin/customParseFormat&#39;);

// プラグインを追加 
dayjs.extend(customParseFormat);

let date = dayjs(&#39;2021-03-19&#39;, &#39;YYYY-MM-DD&#39;, true);
console.log( date.isValid() ); // =&amp;gt; true

let date2 = dayjs(&#39;2021-15-19&#39;, &#39;YYYY-MM-DD&#39;, true);
console.log( date2.isValid() ); // =&amp;gt; false

// 日付の形式が合っていればOKのやりかた。
let date3 = dayjs(&#39;2021-13-19&#39;, &#39;YYYY-MM-DD&#39;);
console.log( date4.isValid() ); // =&amp;gt; true. 日付の形式が合っていればOKとなる。
console.log( date3.toDate() );
// =&amp;gt; 2022-01-18T15:00:00.000Z
// 日付を勝手に繰り上げする.&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/7883969948279208627/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/05/javascriptdayjsapiparse.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/7883969948279208627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/7883969948279208627'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/05/javascriptdayjsapiparse.html' title='【JavaScript】Day.jsのAPIサンプル（Parse編）'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-4719036690869690225</id><published>2021-05-30T10:35:00.001+09:00</published><updated>2021-05-30T10:36:33.014+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="iconv-lite"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>【JavaScript】MS932で文字を判断する。</title><content type='html'>&lt;!-- wp:paragraph --&gt;
&lt;p&gt;JavaScriptを使って、MS932文字コードで文字を判断します。ライブラリは iconv-lite を利用。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;
const iconv = require(&#39;iconv-lite&#39;);

let buf = iconv.encode(&#39;亜&#39;, &#39;ms932&#39; );
console.log( buf );  //=&amp;gt; &amp;lt;Buffer 88 9f&amp;gt;  &amp;#91;0x88, 0x9f]の意味。

// MS932の亜に対応した数値。8ビットシフトするのがポイント。
let enc = buf&amp;#91;0] &amp;lt;&amp;lt; 8 + buf&amp;#91;1];  // 0x889f 
if ( enc === 0x889f ){
  console.log(&#39;亜だね。&#39;);
}&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/4719036690869690225/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/05/javascriptms932.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/4719036690869690225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/4719036690869690225'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/05/javascriptms932.html' title='【JavaScript】MS932で文字を判断する。'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-6236315141113540388</id><published>2021-05-30T10:32:00.002+09:00</published><updated>2021-05-30T10:36:00.602+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Day.js"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>【JavaScript】Day.jsで年齢計算をする。</title><content type='html'>&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　基準日時点で生年月日から年齢はいくつかを計算します。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;

  let base = dayjs(baseDate, YYYYMMDD, true);  // 基準日
  let birth = dayjs(birthday, YYYYMMDD, true); // 生年月日 


  let ibase = Number( base.format(YYYYMMDD) );
  let ibirth = Number( birth.format(YYYYMMDD) );

  return Math.floor( (ibase - ibirth)/10000 );
&lt;/pre&gt;
&lt;!-- /wp:code --&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/6236315141113540388/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/05/javascriptdayjs_30.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/6236315141113540388'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/6236315141113540388'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/05/javascriptdayjs_30.html' title='【JavaScript】Day.jsで年齢計算をする。'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-4111827236545965484</id><published>2021-05-30T10:30:00.002+09:00</published><updated>2021-05-30T10:30:30.260+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Day.js"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>【JavaScript】Day.jsで日付演算処理を行う。</title><content type='html'>&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　元となるソースはGitHub上にあります。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:list --&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://github.com/tomohikoseven/dateUtil_js&quot; target=&quot;_blank&quot; rel=&quot;noreferrer noopener&quot;&gt;https://github.com/tomohikoseven/dateUtil_js&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;!-- /wp:list --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;共通&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　共通的に必要となる定義を示します。フォーマット変換するので、プラグインを入れるのがポイントです。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;
const dayjs = require(&quot;dayjs&quot;);
// プラグインの追加
dayjs.extend(require(&quot;dayjs/plugin/customParseFormat&quot;));

// フォーマット
const YYYYMMDD = &quot;YYYYMMDD&quot;;
const YYYYMMDD_HHmmss = &quot;YYYYMMDD HHmmss&quot;;
const YYYYMMDD_HHmmss_SSS = &quot;YYYYMMDD HHmmss.SSS&quot;;&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;エラー判定処理&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　Day.jsの癖として、日付処理ができない場合は「Invalid Date」という文字列を返します（細かいことはわかりませんが。）。それを利用したエラー判定を行います。これは下で示していく自作APIが処理エラー時にnullを返したいために作られました。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;
function isValidDate(day) {
  if (typeof day === &quot;string&quot;) {
    return day === &quot;Invalid Date&quot; ? null : day;
  }

  return day.isValid() ? day : null;
}&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;年齢計算&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　diff()のポイントは、基準日に対し過去が正の値・未来が負の値となることです。つまり基準日.diff(過去日) &amp;gt; 0 で、基準日.diff(未来日) &amp;lt; 0 です。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;
/**
 * 年齢計算
 * @param {string} baseDate  年齢計算の基準日 YYYYMMDD
 * @param {string} birthday  生年月日 YYYYMMDD
 * @returns 満年齢 or null(計算不可).誕生日に年をとる.
 */
exports.calcAge = (baseDate, birthday) =&gt; {
  let base = dayjs(baseDate, YYYYMMDD, true);
  let birth = dayjs(birthday, YYYYMMDD, true);

  // 日付をパースできない.
  if (!isValidDate(base) || !isValidDate(birth)) {
    return null;
  }

  let ibase = Number( base.format(YYYYMMDD) );
  let ibirth = Number( birth.format(YYYYMMDD) );

  return Math.floor( (ibase - ibirth)/10000 );
};
&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;日付計算（年）&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　日付計算において、年・月・日の加減算はadd()の引数に&quot;year&quot;、&quot;month&quot;、&quot;day&quot;を指定することで計算を行う。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * 日付計算（年）
 * @param {string} baseDate 基準日 YYYYMMDD
 * @param {number} year 加減算する年
 * @returns {string|null} 加減算後の日付 YYYYMMDD
 */
exports.addYears = (baseDate, year) =&amp;gt; {
  return isValidDate(
    dayjs(baseDate, YYYYMMDD, true).add(year, &quot;year&quot;).format(YYYYMMDD)
  );
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;日付計算（月）&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * 日付計算（月）
 * @param {string} baseDate 基準日 YYYYMMDD
 * @param {number} month 加減算する月
 * @returns {string|null} 加減算後の日付 YYYYMMDD
 */
exports.addMonths = (baseDate, month) =&amp;gt; {
  return isValidDate(
    dayjs(baseDate, YYYYMMDD, true).add(month, &quot;month&quot;).format(YYYYMMDD)
  );
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;日付計算（日）&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * 日付計算（日）
 * @param {string} baseDate 基準日 YYYYMMDD
 * @param {number} day 加減算する日
 * @returns {string|null} 加減算後の日付 YYYYMMDD
 */
exports.addDays = (baseDate, day) =&amp;gt; {
  return isValidDate(
    dayjs(baseDate, YYYYMMDD, true).add(day, &quot;day&quot;).format(YYYYMMDD)
  );
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;日付フォーマッター&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * 日付フォーマット
 * @param {string} baseDate 日付日時
 * @param {string} format フォーマット. フォーマット形式はDay.js参照.
 * @returns {string|null} フォーマット後日付
 */
exports.format = (baseDate, format) =&amp;gt; {
  return isValidDate(dayjs(baseDate).format(format));
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;月末算出&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　ライブラリが優秀なので、うるう年も対応しています。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;
/**
 * 月末の日付を返す.
 * @param {string} baseDate 日付 YYYYMMDD or YYYYMM
 * @returns {string|null} 月末日付 YYYYMMDD
 */
exports.endOfMonth = (baseDate) =&amp;gt; {
  return isValidDate(
    dayjs(baseDate, &amp;#91;YYYYMMDD, &quot;YYYYMM&quot;], true).endOf(&quot;month&quot;).format(YYYYMMDD)
  );
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;日付比較&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　isBefore()は基準日と比較して比較対象日付が未来ならばtrue、過去ならばfalseとなります。つまり、基準日.isBefore(過去日 &quot;day&quot;) はtrue、基準日.isBefore(未来日, &quot;day&quot;)はfalseです。 &lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * 日付比較
 * @param {string} baseDate 基準日 YYYYMMDD
 * @param {string} compDate 対象日 YYYYMMDD
 * @returns {number|null} 比較結果. 基準日 &amp;lt; 対象日 は -1, 基準日 = 対象日 は 0, 基準日 &amp;gt; 対象日 は 1
 */
exports.compare = (baseDate, compDate) =&amp;gt; {
  const base = dayjs(baseDate, YYYYMMDD, true);
  const comp = dayjs(compDate, YYYYMMDD, true);

  if (!isValidDate(base) || !isValidDate(comp)) {
    return null;
  }

  if (base.isSame(comp, &quot;days&quot;)) {
    return 0;
  }

  return base.isBefore(comp, &quot;days&quot;) ? -1 : 1;
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;日付差分日数&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　やっていることは年齢計算と同じで、年を計算するか日数を計算するかの違いです。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * 差分日数
 * @param {string} fromDate 基準日 YYYYMMDD
 * @param {string} toDate 対象日 YYYYMMDD
 * @returns {number|null} 計算結果. 基準日 &amp;lt; 対象日は 正の値、基準日 &amp;gt; 対象日は 負の値.
 */
exports.diffDays = (fromDate, toDate) =&amp;gt; {
  let from = dayjs(fromDate, YYYYMMDD, true);
  let to = dayjs(toDate, YYYYMMDD, true);

  if (!isValidDate(from) || !isValidDate(to)) {
    return null;
  }

  return to.diff(from, &quot;day&quot;);
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;エポック &amp;lt;-&amp;gt; UTC時間変換&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　UTC時間を使う場合、プラグインを追加します。またエポック時間には秒とミリ秒で使い方が違うので注意します。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;エポック秒 to UTC時間&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * エポック(秒) to UTC変換
 * @param {number} seconds Unixエポック
 * @returns {string|null} UTC時間 YYYYMMDD hhmmss
 */
exports.epocSecToUtc = (seconds) =&amp;gt; {
  dayjs.extend(require(&quot;dayjs/plugin/utc&quot;));  // 本来はファイルの先頭で宣言
  return isValidDate(dayjs.unix(seconds).utc().format(YYYYMMDD_HHmmss));
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;エポックミリ秒 to UTC変換&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * エポック(ミリ秒) to UTC変換
 * @param {number} miliseconds
 * @returns {string|null} UTC時間 YYYYMMDD hhmmss.SSS
 */
exports.epocMilliSecToUtc = (miliseconds) =&amp;gt; {
  dayjs.extend(require(&quot;dayjs/plugin/utc&quot;));  // 本来はファイルの先頭で宣言
  return isValidDate(dayjs(miliseconds).utc().format(YYYYMMDD_HHmmss_SSS));
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;UTC to エポック秒&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * UTC to エポック(秒)
 * @param {string} baseDate 日付
 * @returns {number|null} エポック(秒)
 */
exports.utcToEpocSec = (baseDate) =&amp;gt; {
  dayjs.extend(require(&quot;dayjs/plugin/utc&quot;));  // 本来はファイルの先頭で宣言
  let utc = dayjs.utc(baseDate);
  if (!isValidDate(utc)) {
    return null;
  }
  return utc.unix();
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;UTC to エポックミリ秒&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * UTC to エポック(ミリ秒)
 * @param {string} baseDate YYYYMMDD HHmmss.SSS
 * @returns {number|null} エポック(ミリ秒)
 */
exports.utcToEpocMilliSec = (baseDate) =&amp;gt; {
  dayjs.extend(require(&quot;dayjs/plugin/utc&quot;));  // 本来はファイルの先頭で宣言
  let utc = dayjs.utc(baseDate);
  if (!isValidDate(utc)) {
    return null;
  }
  return utc.valueOf();
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading --&gt;
&lt;h2&gt;UTC &amp;lt;-&amp;gt; JST 変換&lt;/h2&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:paragraph --&gt;
&lt;p&gt;　Day.jsオブジェクトは実行環境のロケールに合わせてしまうので、クラウドのリージョンなどの環境では注意が必要ですが、今回は環境に依存しないように実装しています。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;UTC to JST&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * UTC to JST変換
 * @param {string} baseUtc UTC時間. YYYYMMDD HHmmss
 * @returns {string|null} 日本時間. YYYYMMDD HHmmss
 */
exports.utcToJst = (baseUtc) =&amp;gt; {
  dayjs.extend(require(&quot;dayjs/plugin/timezone&quot;));  // 本来はファイルの先頭で宣言
  dayjs.extend(require(&quot;dayjs/plugin/utc&quot;));  // 本来はファイルの先頭で宣言
  dayjs.tz.setDefault(&quot;Asia/Tokyo&quot;);

  let utc = dayjs.utc(baseUtc, YYYYMMDD_HHmmss);
  if (!isValidDate(utc)) {
    return null;
  }

  return utc.tz().format(YYYYMMDD_HHmmss);
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;

&lt;!-- wp:heading {&quot;level&quot;:3} --&gt;
&lt;h3&gt;JST to UTC&lt;/h3&gt;
&lt;!-- /wp:heading --&gt;

&lt;!-- wp:code {&quot;className&quot;:&quot;javascript&quot;} --&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;code&gt;/**
 * JST to UTC変換
 * @param {string} baseJst YYYYMMDD HHmmss
 * @returns {string|null} UTC. YYYYMMDD HHmmss
 */
exports.jstToUtc = (baseJst) =&amp;gt; {
  dayjs.extend(require(&quot;dayjs/plugin/timezone&quot;));  // 本来はファイルの先頭で宣言
  dayjs.extend(require(&quot;dayjs/plugin/utc&quot;));  // 本来はファイルの先頭で宣言
  dayjs.tz.setDefault(&quot;Asia/Tokyo&quot;);
  let jst = dayjs(baseJst, YYYYMMDD_HHmmss, true);
  if (!isValidDate(jst)) {
    return null;
  }

  return jst.utc().format(YYYYMMDD_HHmmss);
};&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/4111827236545965484/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/05/javascriptdayjs.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/4111827236545965484'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/4111827236545965484'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/05/javascriptdayjs.html' title='【JavaScript】Day.jsで日付演算処理を行う。'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-2111024744495284333</id><published>2021-04-01T06:51:00.035+09:00</published><updated>2021-05-10T07:24:41.755+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="楽天ラッキーくじ"/><title type='text'>楽天ラッキーくじの当選を整理する。【2021年4月】</title><content type='html'>前月の結果 → &lt;a href=&quot;https://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/03/20213.html&quot;&gt;楽天ラッキーくじの当選を整理する。【2021年3月】&lt;/a&gt;
&lt;div&gt;&lt;a href=&quot;https://note.com/tomohikoseven/n/n416ade99ebed&quot;&gt;noteで楽天ラッキーくじ自動実行プログラム販売中！&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;table border=&quot;1&quot; bordercolor=&quot;#888&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse; border-color: rgb(136, 136, 136); border-width: 1px; margin: 15px;&quot;&gt;
  &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;日付&lt;/th&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;くじ数&lt;/th&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;当選数&lt;/th&gt;&lt;th style=&quot;background-color: #3f51b5; color: white; font-weight: normal; padding: 5px 10px;&quot;&gt;当選サービス&lt;/th&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;4/1&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;リワード特集ページ ラッキーくじ、【楽天ポイント活動部】ラッキーくじ（2021年3月～5月通常版）、楽天カードラッキーくじ、楽天PointClubアプリ　ラッキーくじ、楽天トラベル ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;4/2&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;【楽天toto】楽天totoラッキーくじ、【楽天カード】じゃんけん勝者限定くじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/3&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;リワード特集ページ ラッキーくじ、LINE限定 毎日引けるくじ、楽天カードスマホじゃんけん勝者限定くじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/4&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;楽天トラベル ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/5&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;リワード特集ページ ラッキーくじ、【楽天ポイント活動部】ラッキーくじ（2021年3月～5月通常版）、楽天トラベル ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/6&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;楽天×ぐるなび ラッキーくじ、楽天トラベル ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/7&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;リワード特集ページ ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/8&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;【楽天toto】楽天totoラッキーくじ、楽天PointClubアプリ　ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/9&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;楽天カードスマホラッキーくじ、楽天ブックス・ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/10&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;楽天カードスマホラッキーくじ、【楽天×宝くじ】最大1000ポイントが当たる！楽天×宝くじラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/11&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;リワード特集ページ ラッキーくじ、楽天カードスマホじゃんけん勝者限定くじ、LINE限定 毎日引けるくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/12&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;リワード特集ページ ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
	&lt;tr&gt;&lt;td&gt;4/13&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;リワード特集ページ ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/14&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;楽天ブログ ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/15&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;【楽天レシピ】ラッキーくじ、【楽天レシピ】ラッキーくじ、楽天PointClubアプリ　ラッキーくじ、楽天PointClubアプリ　ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/16&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;【楽天ポイント活動部】ラッキーくじ（2021年3月～5月通常版）、楽天×宝くじ】最大1000ポイントが当たる！楽天×宝くじラッキーくじ、楽天トラベル ラッキーくじ、Rakuten TV ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/17&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;楽天PointClubアプリ　ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/18&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;楽天トラベル ラッキーくじ、リワード特集ページ ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/19&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;楽天PointClubアプリ　ラッキーくじ、【楽天ブックス】facebookラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/20&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;楽天PointClubアプリ　ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/21&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;リワード特集ページ ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/22&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;楽天PointClubアプリ　ラッキーくじ、楽天カードラッキーくじ、【楽天カード】じゃんけん勝者限定くじ、【楽天×宝くじ】最大1000ポイントが当たる！楽天×宝くじラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/23&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;【楽天×宝くじ】最大1000ポイントが当たる！楽天×宝くじラッキーくじ、リワード特集ページ ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/24&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;Rakuten TV ラッキーくじ、【楽天ポイント活動部】ラッキーくじ（2021年3月～5月通常版）、スマートフォン限定 楽天ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/25&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;リワード特集ページ ラッキーくじ、楽天トラベル ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/26&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;リワード特集ページ ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/27&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;リワード特集ページ ラッキーくじ、楽天PointClubアプリ　ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/28&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;【楽天カード】じゃんけん勝者限定くじ、楽天カードスマホラッキーくじ、リワード特集ページ ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/29&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;楽天トラベル ラッキーくじ、楽天PointClubアプリ　ラッキーくじ&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;4/30&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td colspan=&quot;4&quot;&gt;合計：81、平均=2.7&lt;/td&gt;&lt;/tr&gt;
    
  &lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/2111024744495284333/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/04/20214.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/2111024744495284333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/2111024744495284333'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/04/20214.html' title='楽天ラッキーくじの当選を整理する。【2021年4月】'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-698075457300249011</id><published>2021-03-05T07:07:00.001+09:00</published><updated>2021-03-14T15:56:09.245+09:00</updated><title type='text'>Ubuntu Server 20.04 on RPi4 の初期インストール後のwifiネットワーク設定</title><content type='html'>&lt;h2 style=&quot;text-align: left;&quot;&gt;目的&lt;/h2&gt;
&lt;div&gt;ラズパイ4にUbuntu Server 20.04をインストールしたが、wifiのセットアップで時間がかかったので、忘備録として記事を書く。&lt;/div&gt;
&lt;div&gt;（Ubuntu Server 20.10でも同じ手順でwifiセットアップができました。）&lt;/div&gt;
&lt;div&gt;
  &lt;br /&gt;
&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;参考&lt;/h2&gt;
&lt;div&gt;
  &lt;ul style=&quot;text-align: left;&quot;&gt;
    &lt;li&gt;&lt;a href=&quot;https://denor.jp/ubuntu-20-04-focal-fossa%E3%81%AE%E5%88%9D%E6%9C%9F%E8%A8%AD%E5%AE%9A-ip%E3%82%A2%E3%83%89%E3%83%AC%E3%82%B9%E3%80%81%E3%83%9B%E3%82%B9%E3%83%88%E5%90%8D%E7%AD%89&quot; target=&quot;_blank&quot;&gt;Ubuntu 20.04 Focal Fossaの初期設定 IPアドレス、ホスト名等&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://qiita.com/ajitama/items/b9e517db17755a30886f&quot; target=&quot;_blank&quot;&gt;Ubuntu(Bionic)のDNS設定&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
  &lt;br /&gt;
&lt;/div&gt;
  &lt;h2 style=&quot;text-align: left;&quot;&gt;実際のオペレーション&lt;/h2&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
$ sudo cp -p /etc/netplan/50-cloud-init.yaml /etc/netplan/99_config.yaml
$ sudo vi /etc/netplan/99_config.yaml
&lt;/pre&gt;
ファイルの修正内容は以下。wifis以下を追加した。固定IPアドレスの指定なので、そこは自身の環境に合わせる必要がある。&lt;br&gt;また、コロン（:）の直後に半角スペースがないことで、エラーになることがあるので注意。
&lt;pre class=&quot;prettyprint&quot;&gt;
network:
    ethernets:
        eth0:
            dhcp4: true
            optional: true
    version: 2
    wifis:
        wlan0:
            access-points:
                &quot;アクセスポイント名&quot;:
                    password: &quot;パスワード&quot;
            dhcp4: false
            addresses: [192.168.0.118/24]
            gateway4: 192.168.0.1
            nameservers:
                    addresses: [192.168.0.1,8.8.8.8,8.8.4.4]
&lt;/pre&gt;

&lt;pre class=&quot;prettyprint&quot;&gt;
$ sudo netplan apply
$ ping www.google.co.jp # 接続を試す。
&lt;/pre&gt;

</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/698075457300249011/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/03/ubuntu-server-2004-on-rpi4-wifi.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/698075457300249011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/698075457300249011'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2021/03/ubuntu-server-2004-on-rpi4-wifi.html' title='Ubuntu Server 20.04 on RPi4 の初期インストール後のwifiネットワーク設定'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-7365332170088029438</id><published>2020-10-06T08:57:00.096+09:00</published><updated>2022-09-02T07:52:05.167+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="楽天ラッキーくじ"/><title type='text'>楽天ラッキーくじ一覧</title><content type='html'>&lt;div&gt;（2022/9/2）&lt;/div&gt;&lt;div&gt;近日リリース予定のプログラム変更により、[KUJI]が不要となります。&lt;/div&gt;&lt;div&gt;そのため、[KUJI]を削除しました。&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;[KUJI_SP]&lt;/div&gt;&lt;div&gt;楽天Edyスマホラッキーくじ = https://r10.to/hf7Y7J&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;[KUJI_SP2]&lt;/div&gt;&lt;div&gt;楽天PointClubアプリラッキーくじ = https://point.rakuten.co.jp/doc/lottery/lucky/&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/7365332170088029438/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2020/10/202010.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/7365332170088029438'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/7365332170088029438'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2020/10/202010.html' title='楽天ラッキーくじ一覧'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-7322542242500801612</id><published>2020-09-01T06:40:00.001+09:00</published><updated>2020-09-01T06:40:07.919+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Chrome拡張機能を自動でインストールする【Python】【Selenium】【win32com】</title><content type='html'>&lt;p&gt;
　調べても調べても検索に引っ掛からなかった、Chrome拡張機能を自動でインストールする方法がわかったので、ここに記載する。Teratailありがとう。
&lt;/p&gt;

&lt;h2&gt;必要なもの&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Python&lt;/li&gt;
  &lt;li&gt;Selenium&lt;/li&gt;
  &lt;li&gt;chromedriver_binary&lt;/li&gt;
  &lt;li&gt;win32com&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;ソース&lt;/h2&gt;
&lt;p&gt;　「楽天検索」の拡張機能をChromeにインストールするコードを示す。ソースがはみ出してしまっているのはすみません。&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
import time
from time import sleep

# selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
# ないと起動しない
import chromedriver_binary
import selenium.webdriver.support.expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import ctypes
import win32com.client

def getOptions():
    options = webdriver.ChromeOptions()
    options.add_argument( &#39;--user-data-dir=&#39; + &#39;UserData&#39; )
    options.add_argument( &#39;--profile-directory=&#39;+ &#39;Default&#39; )
    return options

def installRakutenSearch():
    # 初回起動、楽天検索拡張機能をインストール
    driver = webdriver.Chrome( options=getOptions() )
    driver.get(r&#39;https://chrome.google.com/webstore/detail/%E6%A5%BD%E5%A4%A9%E3%82%A6%E3%82%A7%E3%83%96%E6%A4%9C%E7%B4%A2/iihkglbebihpaflfihhkfmpabjgdpnol?hl=ja&#39;)

    WebDriverWait(driver, 15).until( EC.element_to_be_clickable( (By.XPATH, &#39;//div[@class=&quot;g-c-Hf&quot;]&#39;) ) )
    driver.find_element_by_xpath( &#39;//div[@class=&quot;g-c-Hf&quot;]&#39; ).click() # Chromeに追加 ボタンクリック

    html = driver.page_source

    handle = ctypes.windll.user32.FindWindowW( &quot;Chrome_WidgetWin_1&quot;,0)
    ctypes.windll.user32.SetForegroundWindow(handle)

    Shell = win32com.client.Dispatch(&quot;WScript.Shell&quot;)
    # うまくいかないときは、range(2)からrange(3)へ変更。調整してください。
    for i in range(2):
        Shell.SendKeys(&quot;{TAB}&quot;) 
        sleep (1)
    Shell.SendKeys(&quot;~&quot;) 
    time.sleep(5)
    driver.close()
    driver.quit()

if __name__ == &#39;__main__&#39;:
    installRakutenSearch()
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/7322542242500801612/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2020/09/chromepythonseleniumwin32com.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/7322542242500801612'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/7322542242500801612'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2020/09/chromepythonseleniumwin32com.html' title='Chrome拡張機能を自動でインストールする【Python】【Selenium】【win32com】'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4720737843399911294.post-7562843975971915533</id><published>2020-08-18T21:29:00.001+09:00</published><updated>2020-08-24T10:39:08.176+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>【Python】一括で svg を png に変換する。</title><content type='html'>&lt;h2&gt;Azure のアイコンが svg で用意されており、パワポで読み込めなかった。&lt;/h2&gt;
&lt;p&gt;　仕事の資料を作成するにあたって、Azureのアイコンを使いたかった。しかし、&lt;a href=&#39;https://docs.microsoft.com/ja-jp/azure/architecture/icons/&#39; target=&#39;_blank&#39;&gt;公式&lt;/a&gt;には svg のアイコンしかない。そのため、プログラム作ってpng画像を作ることにした。&lt;/p&gt;
&lt;p&gt;&lt;a href=&#39;https://drive.google.com/file/d/19gxh8o72eb99_5YOezAeA83NSqdw0A7i/view?usp=sharing&#39; target=&#39;_blank&#39;&gt;Azure icon png(200 x 200)&lt;/a&gt;　ここにpng変換後のアイコンを共有しておく。&lt;/p&gt;
&lt;p&gt;以下にpng変換時のソースを貼っておく。&lt;/p&gt;

&lt;h2&gt;svg → png 変換ソース&lt;/h2&gt;
&lt;p&gt;　本プログラムは一括でsvg -&gt; png 変換を行う。公式のsvgのzipファイルを解凍し、「AI + Machine Learning」フォルダがあるところと同一フォルダで本プログラムを動作させる。&lt;/p&gt;
&lt;p&gt;python 3.7.8で動作確認済み。事前準備として、ライブラリの cairosvg をインストールする必要がある。&lt;/p&gt;

&lt;pre class=&quot;prettyprint&quot;&gt;
pip install cairosvg
&lt;/pre&gt;

&lt;p&gt;　本体プログラムは以下。&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
import os.path
import cairosvg
import os

def main():
    for folder in os.listdir(&#39;.&#39;):
        if os.path.isdir( folder ):
            for file in os.listdir( folder ):
                name = file.split(&#39;.svg&#39;)[0]
                url = folder + r&#39;\{0}.svg&#39;.format(name)
                write_to = folder + r&#39;\{0}.png&#39;.format(name)
                cairosvg.svg2png( url=url
                                , write_to=write_to
                                , output_width=200
                                , output_height=200 )  # svg -&gt; png 本体
                print(file)

if __name__ == &quot;__main__&quot;:
    main()
&lt;/pre&gt;

&lt;p&gt;　svg が不要なら、以下のプログラムを実行すると削除できる。&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
import os.path
import cairosvg
import os

def main():
    for folder in os.listdir(&#39;.&#39;):
        if os.path.isdir( folder ):
            for file in os.listdir( folder ):
                if &#39;.svg&#39; in file:
                    rfile = folder + r&#39;\{0}&#39;.format( file )
                    os.remove( rfile )
                    print(file)

if __name__ == &quot;__main__&quot;:
    main()
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/feeds/7562843975971915533/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2020/08/pythonsvg-png.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/7562843975971915533'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4720737843399911294/posts/default/7562843975971915533'/><link rel='alternate' type='text/html' href='http://tomohikoseven-andre-tomohikoseven.blogspot.com/2020/08/pythonsvg-png.html' title='【Python】一括で svg を png に変換する。'/><author><name>tomohikoseven</name><uri>http://www.blogger.com/profile/09147925596953173066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>