Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

From now suffix #5

Merged
merged 6 commits into from
Nov 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 112 additions & 47 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,49 +1,114 @@
<!DOCTYPE HTML>
<html>
<head>
<script data-main="main" src="src/bower_components/requirejs/require.js"></script>
<title>pat-display-time</title>
</head>
<body>
<main role="main">
<pre><code>
&lt;time class="pat-display-time"
datetime="2015-01-20T08:00Z"&gt;
20 January 2015, 08:00
&lt;/time&gt;</code></pre>
<p>
<time class="pat-display-time"
datetime="2015-01-20T08:00Z">
! 20 January 2015, 08:00
</time>
</p>
<pre><code>
&lt;time class="pat-display-time"
datetime="2015-01-20T08:00Z"
data-pat-display-time="outputFormat:MMMM dddd Do YYYY, h:mm:ss a"&gt;
20 January 2015, 08:00
&lt;/time&gt;</code></pre>
<p>
<time class="pat-display-time"
datetime="2015-01-20T08:00Z"
data-pat-display-time="outputFormat:MMMM dddd Do YYYY, h:mm:ss">
! 20 January 2015, 08:00
</time>
</p>

<pre><code>
&lt;time class="pat-display-time"
datetime="2015-01-20T08:00Z"
data-pat-display-time="displayFormat:L"&gt;
20 January 2015, 08:00
&lt;/time&gt;</code></pre>
<p>
<time class="pat-display-time"
datetime="2015-01-20T08:00Z"
data-pat-display-time="outputFormat:L">
! 20 January 2015, 08:00
</time>
</p>

</main>
</body>

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>pat-display-time demo</title>
<script data-main="main" src="src/bower_components/requirejs/require.js"></script>
</head>

<body role="document">

<h1>pat-display-time demo</h1>

<h2>Example of default</h2>
<h3>Code</h3>
<pre>
<code>
&lt;time class="pat-display-time"
datetime="2015-01-20T08:00Z"&gt;
20 January 2015, 08:00
&lt;/time&gt;
</code>
</pre>

<h3>Output</h3>
<p>
<time class="pat-display-time" datetime="2015-01-20T08:00Z">
20 January 2015, 08:00
</time>
</p>

<hr>

<h2>Example setting the output format explicitly</h2>
<h3>Code</h3>
<pre>
<code>
&lt;time class="pat-display-time"
datetime="2015-01-20T08:00Z"
data-pat-display-time="output-format: MMMM dddd Do YYYY, h:mm:ss a"&gt;
20 January 2015, 08:00
&lt;/time&gt;
</code>
</pre>
<h3>Output</h3>
<p>
<time class="pat-display-time" datetime="2015-01-20T08:00Z" data-pat-display-time="output-format: MMMM dddd Do YYYY, h:mm:ss">
20 January 2015, 08:00
</time>
</p>

<hr>

<h2>Output formatted as local</h2>
<h3>Code</h3>
<pre>
<code>
&lt;time class="pat-display-time"
datetime="2015-01-20T08:00Z"
data-pat-display-time="output-format: L"&gt;
20 January 2015, 08:00
&lt;/time&gt;
</code>
</pre>
<h3>Output</h3>
<p>
<time class="pat-display-time" datetime="2015-01-20T08:00Z" data-pat-display-time="output-format: L">
20 January 2015, 08:00
</time>
</p>

<hr>

<h2>Output formatted as 'from now'</h2>
<h3>Code</h3>
<pre>
<code>
&lt;time class="pat-display-time"
datetime="2015-01-20T08:00Z"
data-pat-display-time="from-now: true"&gt;
20 January 2015, 08:00
&lt;/time&gt;
</code>
</pre>
<h3>Output</h3>
<p>
<time class="pat-display-time" datetime="2015-01-20T08:00Z" data-pat-display-time="from-now: true">
20 January 2015, 08:00
</time>
</p>

<hr>

<h2>Output formatted as 'from now' with no suffix</h2>
<h3>Code</h3>
<pre>
<code>
&lt;time class="pat-display-time"
datetime="2015-01-20T08:00Z"
data-pat-display-time="from-now: true; no-suffix: true"&gt;
20 January 2015, 08:00
&lt;/time&gt;
</code>
</pre>
<h3>Output</h3>
<p>
<time class="pat-display-time" datetime="2015-01-20T08:00Z" data-pat-display-time="from-now: true; no-suffix: true">
20 January 2015, 08:00
</time>
</p>

</body>

</html>
8 changes: 4 additions & 4 deletions src/pat-display-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

// output options
parser.add_argument("from-now", false);
parser.add_argument("no-suffix", false);
parser.add_argument("output-format", "");
parser.add_argument("output-locale", "");

return Base.extend({
name: "display-time",
Expand All @@ -49,9 +49,9 @@
var date_str = this.$el.attr("datetime");
var date = moment(date_str, this.options.format, this.options.locale, this.options.strict);
if (this.options.fromNow === true) {
date = date.fromNow();
} else if (this.options.output.format.length) {
date = date.format(this.options.output.format);
date = date.fromNow(this.options.noSuffix);
} else if (this.options.outputFormat.length) {
date = date.format(this.options.outputFormat);
}
this.$el.text(date);
}
Expand Down