1 | /* |
---|
2 | * Garfield comic engine for WebStrips |
---|
3 | |
---|
4 | * comic webpage: http://www.garfield.com/ |
---|
5 | * |
---|
6 | * author: Luka Cehovin |
---|
7 | * |
---|
8 | * License: |
---|
9 | * |
---|
10 | * This program is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; either version 2 of the License, or (at |
---|
13 | * your option) any later version. |
---|
14 | * |
---|
15 | * This program is distributed in the hope that it will be useful, but |
---|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
18 | * Public License for more details. |
---|
19 | * |
---|
20 | * http://www.opensource.org/licenses/gpl-license.php |
---|
21 | * |
---|
22 | * You should have received a copy of the GNU General Public License along |
---|
23 | * with this program; if not, write to the Free Software Foundation, |
---|
24 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | var FIRST_DATE = new Date("1978/06/19"); |
---|
29 | |
---|
30 | // length of day in miliseconds |
---|
31 | var DAY = 1000 * 60 * 60 * 24; |
---|
32 | |
---|
33 | function parseDate(str) { |
---|
34 | |
---|
35 | var m = str.match(/(\d\d)(\d\d)(\d\d)/); |
---|
36 | if (m) { |
---|
37 | |
---|
38 | return new Date((( (m[1] > 70) ? 1900 : 2000) + parseInt(m[1])) + "/" + m[2] + "/" + m[3]); |
---|
39 | |
---|
40 | } else return FIRST_DATE; |
---|
41 | |
---|
42 | } |
---|
43 | |
---|
44 | function title(cs) { |
---|
45 | |
---|
46 | return formatDate(parseDate(cs)); |
---|
47 | } |
---|
48 | |
---|
49 | function image(cs) { |
---|
50 | |
---|
51 | var c = parseDate(cs); |
---|
52 | |
---|
53 | if (c == null) |
---|
54 | return null; |
---|
55 | |
---|
56 | return format("http://images.ucomics.com/comics/ga/%1$tY/ga%1$ty%1$tm%1$td.gif", c); |
---|
57 | |
---|
58 | } |
---|
59 | |
---|
60 | function previous(cs) { |
---|
61 | var c = parseDate(cs); |
---|
62 | |
---|
63 | if (c == null) |
---|
64 | return null; |
---|
65 | |
---|
66 | if (c.getTime() > FIRST_DATE.getTime()) { |
---|
67 | c.setTime(c.getTime() - DAY); |
---|
68 | return format("%1$ty%1$tm%1$td", c); |
---|
69 | } |
---|
70 | |
---|
71 | return null; |
---|
72 | } |
---|
73 | |
---|
74 | function next(cs) { |
---|
75 | var c = parseDate(cs); |
---|
76 | |
---|
77 | if (c == null) return null; |
---|
78 | |
---|
79 | if (c.getTime() < (new Date()).getTime()) { |
---|
80 | c.setTime(c.getTime() + DAY); |
---|
81 | |
---|
82 | var s = format("http://images.ucomics.com/comics/ga/%1$tY/ga%1$ty%1$tm%1$td.gif", c); |
---|
83 | |
---|
84 | if (!exists(s)) |
---|
85 | return null; |
---|
86 | |
---|
87 | return format("%1$ty%1$tm%1$td", c); |
---|
88 | } |
---|
89 | |
---|
90 | return null; |
---|
91 | } |
---|
92 | |
---|
93 | function first() { |
---|
94 | return format("%1$ty%1$tm%1$td", FIRST_DATE); |
---|
95 | } |
---|
96 | |
---|
97 | function newest() { |
---|
98 | |
---|
99 | var c = new Date(); |
---|
100 | |
---|
101 | var s = format("http://images.ucomics.com/comics/ga/%1$tY/ga%1$ty%1$tm%1$td.gif", c); |
---|
102 | |
---|
103 | if (!exists(s)) |
---|
104 | c.setTime(c.getTime() - DAY); |
---|
105 | |
---|
106 | return format("%1$ty%1$tm%1$td", c); |
---|
107 | } |
---|