Mercurial Hosting > nabble
comparison src/nabble/view/web/template/DateNamespace.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ecd1a4ef557 |
---|---|
1 package nabble.view.web.template; | |
2 | |
3 import nabble.naml.compiler.Command; | |
4 import nabble.naml.compiler.CommandSpec; | |
5 import nabble.naml.compiler.IPrintWriter; | |
6 import nabble.naml.compiler.Interpreter; | |
7 import nabble.naml.compiler.Namespace; | |
8 | |
9 import java.text.SimpleDateFormat; | |
10 import java.util.Date; | |
11 | |
12 | |
13 @Namespace ( | |
14 name = "date", | |
15 global = false | |
16 ) | |
17 public final class DateNamespace { | |
18 private final Date date; | |
19 | |
20 public DateNamespace(Date date) { | |
21 this.date = date; | |
22 } | |
23 | |
24 @Command public void raw_time(IPrintWriter out,Interpreter interp) { | |
25 out.print( date.getTime() ); | |
26 } | |
27 | |
28 public static final CommandSpec custom_format = new CommandSpec.Builder() | |
29 .parameters("format") | |
30 .build() | |
31 ; | |
32 | |
33 @Command public void custom_format(IPrintWriter out, Interpreter interp) { | |
34 String format = interp.getArgString("format"); | |
35 out.print(new SimpleDateFormat(format).format(date)); | |
36 } | |
37 | |
38 public static final CommandSpec is_older_than = new CommandSpec.Builder() | |
39 .parameters("days") | |
40 .build() | |
41 ; | |
42 | |
43 @Command public void is_older_than(IPrintWriter out, Interpreter interp) { | |
44 int days = interp.getArgAsInt("days"); | |
45 long diffFromNow = System.currentTimeMillis() - date.getTime(); | |
46 float daysFromNow = diffFromNow / (24 * 60 * 60 * 1000); | |
47 out.print(daysFromNow > days); | |
48 } | |
49 | |
50 } |