damagecontrol 0.5.0 → 0.5.0.1391

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/README +67 -11
  2. data/Rakefile +15 -6
  3. data/app/controllers/admin_controller.rb +0 -3
  4. data/app/controllers/application.rb +42 -163
  5. data/app/controllers/build_controller.rb +33 -0
  6. data/app/controllers/files_controller.rb +1 -1
  7. data/app/controllers/project_controller.rb +23 -65
  8. data/app/controllers/rails_ext.rb +247 -0
  9. data/app/controllers/rscm_ext.rb +52 -0
  10. data/app/helpers/build_helper.rb +2 -0
  11. data/app/views/build/email.rhtml +18 -0
  12. data/app/views/build/status.rhtml +20 -0
  13. data/app/views/build/tests.rhtml +2 -0
  14. data/app/views/layouts/{rscm.rhtml → default.rhtml} +10 -4
  15. data/app/views/project/_changesets_list.rhtml +2 -2
  16. data/app/views/project/_cvs.rhtml +4 -5
  17. data/app/views/project/_project.rhtml +9 -9
  18. data/app/views/project/_select_pane.rhtml +26 -0
  19. data/app/views/project/_tab_pane.rhtml +23 -0
  20. data/app/views/project/changeset.rhtml +35 -0
  21. data/app/views/project/view.rhtml +18 -32
  22. data/app/views/setup/welcome.rhtml +118 -0
  23. data/config/database.yml +20 -20
  24. data/config/environment.rb +66 -60
  25. data/config/environments/development.rb +3 -2
  26. data/config/environments/production.rb +3 -2
  27. data/config/environments/test.rb +3 -2
  28. data/config/routes.rb +15 -0
  29. data/lib/damagecontrol/app.rb +11 -40
  30. data/lib/damagecontrol/build.rb +50 -8
  31. data/lib/damagecontrol/directories.rb +7 -6
  32. data/lib/damagecontrol/poller.rb +11 -20
  33. data/lib/damagecontrol/project.rb +83 -16
  34. data/lib/damagecontrol/publisher/ambient_orb.rb +16 -0
  35. data/lib/damagecontrol/publisher/archive.rb +16 -0
  36. data/lib/damagecontrol/publisher/base.rb +25 -0
  37. data/lib/damagecontrol/publisher/build_duration.rb +16 -0
  38. data/lib/damagecontrol/publisher/email.rb +59 -0
  39. data/lib/damagecontrol/publisher/execute.rb +49 -0
  40. data/lib/damagecontrol/publisher/ftp.rb +16 -0
  41. data/lib/damagecontrol/publisher/growl.rb +44 -0
  42. data/lib/damagecontrol/publisher/irc.rb +31 -0
  43. data/lib/damagecontrol/publisher/jabber.rb +68 -0
  44. data/lib/damagecontrol/publisher/scp.rb +16 -0
  45. data/lib/damagecontrol/publisher/x10cm11a.rb +17 -0
  46. data/lib/damagecontrol/publisher/x10cm17a.rb +17 -0
  47. data/lib/damagecontrol/publisher/yahoo.rb +16 -0
  48. data/lib/damagecontrol/standard_persister.rb +2 -2
  49. data/lib/damagecontrol/tracker.rb +48 -6
  50. data/lib/damagecontrol/visitor/rss_writer.rb +1 -1
  51. data/lib/damagecontrol/visitor/yaml_persister.rb +10 -1
  52. data/public/404.html +5 -5
  53. data/public/500.html +5 -5
  54. data/public/dispatch.cgi +2 -2
  55. data/public/dispatch.fcgi +1 -1
  56. data/public/dispatch.rb +2 -2
  57. data/public/images/growlicon.png +0 -0
  58. data/public/images/megaphone.png +0 -0
  59. data/public/images/monotone-logo.png +0 -0
  60. data/public/images/publisher/ambient_orb.png +0 -0
  61. data/public/images/publisher/build_duration.png +0 -0
  62. data/public/images/publisher/email.png +0 -0
  63. data/public/images/publisher/execute.png +0 -0
  64. data/public/images/publisher/growl.png +0 -0
  65. data/public/images/publisher/irc.png +0 -0
  66. data/public/images/publisher/jabber.png +0 -0
  67. data/public/images/publisher/x10cm11a.png +0 -0
  68. data/public/images/publisher/x10cm17a.png +0 -0
  69. data/public/images/publisher/yahoo.png +0 -0
  70. data/public/index.html +70 -1
  71. data/public/javascripts/dateFormat.js +283 -0
  72. data/public/javascripts/jscalendar/ChangeLog +500 -0
  73. data/public/javascripts/jscalendar/README +33 -0
  74. data/public/javascripts/jscalendar/bugtest-hidden-selects.html +108 -0
  75. data/public/javascripts/jscalendar/calendar-blue.css +231 -0
  76. data/public/javascripts/jscalendar/calendar-blue2.css +235 -0
  77. data/public/javascripts/jscalendar/calendar-brown.css +224 -0
  78. data/public/javascripts/jscalendar/calendar-green.css +228 -0
  79. data/public/javascripts/jscalendar/calendar-setup.js +181 -0
  80. data/public/javascripts/jscalendar/calendar-setup_stripped.js +21 -0
  81. data/public/javascripts/jscalendar/calendar-system.css +250 -0
  82. data/public/javascripts/jscalendar/calendar-tas.css +238 -0
  83. data/public/javascripts/jscalendar/calendar-win2k-1.css +270 -0
  84. data/public/javascripts/jscalendar/calendar-win2k-2.css +270 -0
  85. data/public/javascripts/jscalendar/calendar-win2k-cold-1.css +264 -0
  86. data/public/javascripts/jscalendar/calendar-win2k-cold-2.css +270 -0
  87. data/public/javascripts/jscalendar/calendar.js +1715 -0
  88. data/public/javascripts/jscalendar/calendar.php +119 -0
  89. data/public/javascripts/jscalendar/calendar_stripped.js +12 -0
  90. data/public/javascripts/jscalendar/doc/html/reference-Z-S.css +0 -0
  91. data/public/javascripts/jscalendar/doc/html/reference.css +34 -0
  92. data/public/javascripts/jscalendar/doc/html/reference.html +1316 -0
  93. data/public/javascripts/jscalendar/doc/reference.pdf +0 -0
  94. data/public/javascripts/jscalendar/img.gif +0 -0
  95. data/public/javascripts/jscalendar/index.html +333 -0
  96. data/public/javascripts/jscalendar/lang/calendar-af.js +39 -0
  97. data/public/javascripts/jscalendar/lang/calendar-br.js +45 -0
  98. data/public/javascripts/jscalendar/lang/calendar-ca.js +45 -0
  99. data/public/javascripts/jscalendar/lang/calendar-cs-win.js +34 -0
  100. data/public/javascripts/jscalendar/lang/calendar-da.js +63 -0
  101. data/public/javascripts/jscalendar/lang/calendar-de.js +100 -0
  102. data/public/javascripts/jscalendar/lang/calendar-du.js +45 -0
  103. data/public/javascripts/jscalendar/lang/calendar-el.js +89 -0
  104. data/public/javascripts/jscalendar/lang/calendar-en.js +123 -0
  105. data/public/javascripts/jscalendar/lang/calendar-es.js +114 -0
  106. data/public/javascripts/jscalendar/lang/calendar-fi.js +98 -0
  107. data/public/javascripts/jscalendar/lang/calendar-fr.js +86 -0
  108. data/public/javascripts/jscalendar/lang/calendar-hr-utf8.js +49 -0
  109. data/public/javascripts/jscalendar/lang/calendar-hr.js +0 -0
  110. data/public/javascripts/jscalendar/lang/calendar-hu.js +45 -0
  111. data/public/javascripts/jscalendar/lang/calendar-it.js +79 -0
  112. data/public/javascripts/jscalendar/lang/calendar-jp.js +45 -0
  113. data/public/javascripts/jscalendar/lang/calendar-ko-utf8.js +120 -0
  114. data/public/javascripts/jscalendar/lang/calendar-ko.js +120 -0
  115. data/public/javascripts/jscalendar/lang/calendar-lt-utf8.js +114 -0
  116. data/public/javascripts/jscalendar/lang/calendar-lt.js +114 -0
  117. data/public/javascripts/jscalendar/lang/calendar-nl.js +45 -0
  118. data/public/javascripts/jscalendar/lang/calendar-no.js +45 -0
  119. data/public/javascripts/jscalendar/lang/calendar-pl-utf8.js +93 -0
  120. data/public/javascripts/jscalendar/lang/calendar-pl.js +56 -0
  121. data/public/javascripts/jscalendar/lang/calendar-pt.js +45 -0
  122. data/public/javascripts/jscalendar/lang/calendar-ro.js +66 -0
  123. data/public/javascripts/jscalendar/lang/calendar-ru.js +45 -0
  124. data/public/javascripts/jscalendar/lang/calendar-si.js +94 -0
  125. data/public/javascripts/jscalendar/lang/calendar-sk.js +99 -0
  126. data/public/javascripts/jscalendar/lang/calendar-sp.js +63 -0
  127. data/public/javascripts/jscalendar/lang/calendar-sv.js +93 -0
  128. data/public/javascripts/jscalendar/lang/calendar-tr.js +58 -0
  129. data/public/javascripts/jscalendar/lang/calendar-zh.js +45 -0
  130. data/public/javascripts/jscalendar/menuarrow.gif +0 -0
  131. data/public/javascripts/jscalendar/menuarrow2.gif +0 -0
  132. data/public/javascripts/jscalendar/release-notes.html +334 -0
  133. data/public/javascripts/jscalendar/simple-1.html +244 -0
  134. data/public/javascripts/jscalendar/simple-2.html +108 -0
  135. data/public/javascripts/jscalendar/simple-3.html +130 -0
  136. data/public/javascripts/jscalendar/test-position.html +40 -0
  137. data/public/javascripts/jscalendar/test.php +116 -0
  138. data/public/javascripts/toggle_div.js +18 -0
  139. data/public/stylesheets/niceones.txt +1 -0
  140. data/public/stylesheets/style.css +8 -1
  141. data/script/breakpointer +4 -5
  142. data/script/console +19 -27
  143. data/script/console_sandbox.rb +7 -0
  144. data/script/destroy +5 -0
  145. data/script/generate +3 -68
  146. data/script/server +6 -16
  147. data/test/damagecontrol/build_test.rb +8 -8
  148. data/test/damagecontrol/poller_test.rb +10 -18
  149. data/test/damagecontrol/project_test.rb +49 -13
  150. data/test/damagecontrol/publisher/base_test.rb +26 -0
  151. data/test/damagecontrol/publisher/build/email.rhtml +0 -0
  152. data/test/damagecontrol/publisher/email_test.rb +26 -0
  153. data/test/damagecontrol/publisher/fixture.rb +34 -0
  154. data/test/damagecontrol/publisher/growl_test.rb +15 -0
  155. data/test/damagecontrol/publisher/jabber_test.rb +15 -0
  156. data/test/damagecontrol/scm_web_test.rb +1 -1
  157. data/test/damagecontrol/visitor/changesets.rss +1 -1
  158. data/test/damagecontrol/visitor/diff_persister_test.rb +4 -4
  159. data/test/functional/build_controller_test.rb +17 -0
  160. data/test/test_helper.rb +13 -13
  161. metadata +185 -24
  162. data/app/views/project/_bugzilla.rhtml +0 -13
  163. data/app/views/project/_jira.rhtml +0 -19
  164. data/app/views/project/_mooky.rhtml +0 -23
  165. data/app/views/project/_rubyforge.rhtml +0 -19
  166. data/app/views/project/_scarab.rhtml +0 -19
  167. data/app/views/project/_scms.rhtml +0 -15
  168. data/app/views/project/_sourceforge.rhtml +0 -19
  169. data/app/views/project/_starteam.rhtml +0 -43
  170. data/app/views/project/_svn.rhtml +0 -22
  171. data/app/views/project/_trac.rhtml +0 -13
  172. data/app/views/project/_trackers.rhtml +0 -18
  173. data/app/views/project/changesets.rhtml +0 -31
@@ -19,7 +19,7 @@ module DamageControl
19
19
  @rss.channel.title = @title
20
20
  @rss.channel.link = @link
21
21
  @rss.channel.description = @description
22
- @rss.channel.generator = "RSCM - Ruby Source Control Management"
22
+ @rss.channel.generator = "DamageControl"
23
23
  end
24
24
 
25
25
  def visit_changeset(changeset)
@@ -37,6 +37,7 @@ module DamageControl
37
37
  # the last changeset.
38
38
  #
39
39
  def load_upto(last_changeset_identifier, prior)
40
+ Log.info "Loading #{prior} changesets from #{@changesets_dir} (from #{last_changeset_identifier} and down)"
40
41
  last = identifiers.index(last_changeset_identifier)
41
42
 
42
43
  changesets = RSCM::ChangeSets.new
@@ -45,7 +46,15 @@ module DamageControl
45
46
  first = 0 if first < 0
46
47
 
47
48
  identifiers[first..last].each do |identifier|
48
- changesets.add(YAML::load_file("#{@changesets_dir}/#{identifier.to_s}/changeset.yaml"))
49
+ changeset_yaml = "#{@changesets_dir}/#{identifier.to_s}/changeset.yaml"
50
+ Log.info "Loading changesets from #{changeset_yaml}"
51
+ begin
52
+ changesets.add(YAML::load_file(changeset_yaml))
53
+ rescue Exception => e
54
+ # Sometimes the yaml files get corrupted
55
+ Log.error "Error loading changesets file: #{File.expand_path(changeset_yaml)}"
56
+ # Todo: delete it and schedule it for re-retrieval somehow.
57
+ end
49
58
  end
50
59
  end
51
60
  changesets
@@ -1,6 +1,6 @@
1
- <html>
2
- <body>
3
- <h1>File not found</h1>
4
- <p>Change this error message for pages not found in public/404.html</p>
5
- </body>
1
+ <html>
2
+ <body>
3
+ <h1>File not found</h1>
4
+ <p>Change this error message for pages not found in public/404.html</p>
5
+ </body>
6
6
  </html>
@@ -1,6 +1,6 @@
1
- <html>
2
- <body>
3
- <h1>Application error (Apache)</h1>
4
- <p>Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html</p>
5
- </body>
1
+ <html>
2
+ <body>
3
+ <h1>Application error (Apache)</h1>
4
+ <p>Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html</p>
5
+ </body>
6
6
  </html>
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!c:/ruby/bin/ruby
2
2
 
3
3
  require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
4
4
 
@@ -6,5 +6,5 @@ require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_
6
6
  # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
7
7
  require "dispatcher"
8
8
 
9
- ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) }
9
+ ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
10
10
  Dispatcher.dispatch
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!c:/ruby/bin/ruby
2
2
 
3
3
  require File.dirname(__FILE__) + "/../config/environment"
4
4
  require 'dispatcher'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!c:/ruby/bin/ruby
2
2
 
3
3
  require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
4
4
 
@@ -6,5 +6,5 @@ require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_
6
6
  # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
7
7
  require "dispatcher"
8
8
 
9
- ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) }
9
+ ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
10
10
  Dispatcher.dispatch
@@ -1 +1,70 @@
1
- <html><head><META HTTP-EQUIV="Refresh" CONTENT="0;URL=_doc/index.html"></head></html>
1
+ <html>
2
+ <head>
3
+ <title>Rails: Welcome on board</title>
4
+ <style>
5
+ body { background-color: #fff; color: #333; }
6
+
7
+ body, p, ol, ul, td {
8
+ font-family: verdana, arial, helvetica, sans-serif;
9
+ font-size: 12px;
10
+ line-height: 18px;
11
+ }
12
+
13
+ li {
14
+ margin-bottom: 7px;
15
+ }
16
+
17
+ pre {
18
+ background-color: #eee;
19
+ padding: 10px;
20
+ font-size: 11px;
21
+ }
22
+
23
+ a { color: #000; }
24
+ a:visited { color: #666; }
25
+ a:hover { color: #fff; background-color:#000; }
26
+ </style>
27
+ </head>
28
+ <body>
29
+
30
+ <h1>Congratulations, you've put Ruby on Rails!</h1>
31
+
32
+ <p><b>Before you move on</b>, verify that the following conditions have been met:</p>
33
+
34
+ <ol>
35
+ <li>The log and public directories must be writable to the web server (<code>chmod -R 775 log</code> and <code>chmod -R 775 public</code>).
36
+ <li>
37
+ The shebang line in the public/dispatch* files must reference your Ruby installation. <br/>
38
+ You might need to change it to <code>#!/usr/bin/env ruby</code> or point directly at the installation.
39
+ </li>
40
+ <li>
41
+ Rails on Apache needs to have the cgi handler and mod_rewrite enabled. <br/>
42
+ Somewhere in your httpd.conf, you should have:<br/>
43
+ <code>AddHandler cgi-script .cgi</code><br/>
44
+ <code>LoadModule rewrite_module libexec/httpd/mod_rewrite.so</code><br/>
45
+ <code>AddModule mod_rewrite.c</code>
46
+ </li>
47
+ </ol>
48
+
49
+ <p>Take the following steps to get started:</p>
50
+
51
+ <ol>
52
+ <li>Create empty development and test databases for your application.<br/>
53
+ <small>Recommendation: Use *_development and *_test names, such as basecamp_development and basecamp_test</small><br/>
54
+ <small>Warning: Don't point your test database at your development database, it'll destroy the latter on test runs!</small>
55
+ <li>Edit config/database.yml with your database settings.
56
+ <li>Create controllers and models using the generator in <code>script/generate</code> <br/>
57
+ <small>Help: Run the generator with no arguments for documentation</small>
58
+ <li>See all the tests run by running <code>rake</code>.
59
+ <li>Develop your Rails application!
60
+ <li>Setup Apache with <a href="http://www.fastcgi.com">FastCGI</a> (and <a href="http://raa.ruby-lang.org/list.rhtml?name=fcgi">Ruby bindings</a>), if you need better performance
61
+ </ol>
62
+
63
+ <p>
64
+ Having problems getting up and running? First try debugging it yourself by looking at the log files. <br/>
65
+ Then try the friendly Rails community <a href="http://www.rubyonrails.org">on the web</a> or <a href="http://www.rubyonrails.org/show/IRC">on IRC</a>
66
+ (<a href="irc://irc.freenode.net/#rubyonrails">FreeNode#rubyonrails</a>).
67
+ </p>
68
+
69
+ </body>
70
+ </html>
@@ -0,0 +1,283 @@
1
+ /*
2
+ http://www.shoestringcms.com/personal/codelib/JavaScript/DemoDate.html
3
+
4
+ dateFormat.js - Format a date to a user-defined string formats.
5
+ Written by John Brooking, March 2001
6
+ See DemoDate.htm for a demo of use.
7
+
8
+ This program is released into the public domain. You are prohibited
9
+ from selling it, and please include the existing revision history
10
+ with any modifications you make, plus add your own. You are
11
+ encouraged to share any modifications with me and others, and to
12
+ report problems to me, at http://www.pobox.com/~JohnBrook.
13
+
14
+ $Log3: F:\QVCS\Code Library\JavaScript\dateFormat.kt $
15
+
16
+ A JavaScript routine to format dates to a variety of strings.
17
+
18
+ Revision 1.4 by: John Brooking Rev date: Thu Oct 03 08:18:00 2002
19
+ Fixed bug in ordinals: All teens should get "th", not standard
20
+ rules. (This was not really checked into QVCS, because my
21
+ personal library is not functional currently. I'm just faking
22
+ this entry.)
23
+
24
+ Revision 1.3 by: John Brooking Rev date: Fri Aug 31 16:40:00 2001
25
+ Fixed bug in "quarter" equations.
26
+
27
+ Revision 1.2 by: John Brooking Rev date: Sat Apr 21 07:55:24 2001
28
+ Fixed bug in %h% and %hh% formats (show hour as number 1-12) due to
29
+ JavaScript handling of negative numbers. Midnight was being printed as
30
+ "0" rather than "12". Thanks to Michael Ennis for reporting this.
31
+
32
+ Revision 1.1 by: John Brooking Rev date: Thu Mar 15 22:55:24 2001
33
+ Added new formats %dth% and %ddth%, and added more verbosity about
34
+ public domain use at the top.
35
+
36
+ $Endlog$
37
+
38
+ */
39
+
40
+
41
+ Date.prototype.format = function(fmt) {
42
+ return dateFormat(fmt, this);
43
+ }
44
+
45
+
46
+ ESCAPE_CHR = "%";
47
+ ERR_UNCLOSED = "Error: Format string not terminated!";
48
+ ERR_UNKNOWN = "Error: Unknown format string!";
49
+
50
+ function isLeapYear(y)
51
+ {
52
+ return (( y % 100 == 0 ) ? (y % 400 == 0) : (y % 4 == 0));
53
+ }
54
+
55
+ function dayOfYear(theDate)
56
+ {
57
+ var monthlens = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
58
+ var yearDay = 0
59
+
60
+ // Total days in months prior to this one
61
+ for( var mon = 0; mon < theDate.getMonth(); ++mon )
62
+ yearDay += monthlens[mon];
63
+
64
+ // Add one if March or later of a leap year
65
+ if( isLeapYear(theDate.getFullYear()) && theDate.getMonth() >= 2 )
66
+ ++yearDay;
67
+
68
+ // Add days of current month
69
+ yearDay += theDate.getDate();
70
+
71
+ return yearDay;
72
+ }
73
+
74
+ function padnum2(n)
75
+ {
76
+ return (n < 10) ? "0" + n : "" + n;
77
+ }
78
+
79
+ function dateFormat(fmt, theDate)
80
+ {
81
+ var fmtIndex = 0, fmtLen = fmt.length;
82
+ var c, thisFmt, mon, yearDay;
83
+ var weekdays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" );
84
+ var monthnames = new Array("January", "February", "March", "April",
85
+ "May", "June", "July", "August", "September",
86
+ "October", "November", "December");
87
+ var result = "";
88
+
89
+ // If date parameter passed not an object, return blank.
90
+ if( typeof(theDate) != "object" )
91
+ return "";
92
+ // This is almost the extent of our real sophisticated error checking!
93
+
94
+ // Loop over each character in format string
95
+ while( fmtIndex < fmtLen )
96
+ {
97
+ c = fmt.substr( fmtIndex, 1);
98
+
99
+ // If it is a leading escape character,
100
+ if( c == ESCAPE_CHR )
101
+ {
102
+ thisFmt = "";
103
+ if( ++fmtIndex == fmtLen )
104
+ return ERR_UNCLOSED;
105
+
106
+ // Build up the format string
107
+ while(( c = fmt.substr( fmtIndex, 1)) != ESCAPE_CHR )
108
+ {
109
+ thisFmt += c;
110
+ if( ++fmtIndex == fmtLen )
111
+ return ERR_UNCLOSED;
112
+ }
113
+
114
+ // Now just take the specified action!
115
+ // (Yes, a switch statement would be more appropriate here, but
116
+ // since that is a later addition to JS, I'm avoiding it here to
117
+ // be as compatible as possible.)
118
+
119
+ if( thisFmt == "d" ) // Day of month w/o leading 0
120
+ result += theDate.getDate();
121
+
122
+ else if (thisFmt == "dd" ) // Day of month with leading 0
123
+ result += padnum2(theDate.getDate());
124
+
125
+ else if (thisFmt == "ddd" ) // Day of week abbreviated
126
+ result += weekdays[theDate.getDay()].substr(0,3);
127
+
128
+ else if (thisFmt == "dddd" ) // Day of week full
129
+ result += weekdays[theDate.getDay()];
130
+
131
+ else if (thisFmt == "dth" ) // Day of month as ordinal w/o leading 0
132
+ {
133
+ var d = theDate.getDate();
134
+ result += d;
135
+ if( d > 10 && d < 20 ) { // teens all get "th"
136
+ result += "th";
137
+ }
138
+ else { // else, normal rules apply
139
+ switch (d % 10) {
140
+ case 1: result += "st"; break;
141
+ case 2: result += "nd"; break;
142
+ case 3: result += "rd"; break;
143
+ default: result += "th"; break;
144
+ }
145
+ }
146
+ /*
147
+ if(( d % 10) == 1 )
148
+ result += "st";
149
+ else if(( d % 10) == 2 )
150
+ result += "nd";
151
+ else if(( d % 10) == 3 )
152
+ result += "rd";
153
+ else
154
+ result += "th";
155
+ */
156
+ }
157
+
158
+ else if (thisFmt == "ddth" ) // Day of month as ordinal with leading 0
159
+ {
160
+ var d = theDate.getDate();
161
+ result += padnum2(d);
162
+ if( d > 10 && d < 20 ) { // teens all get "th"
163
+ result += "th";
164
+ }
165
+ else { // else, normal rules apply
166
+ switch (d % 10) {
167
+ case 1: result += "st"; break;
168
+ case 2: result += "nd"; break;
169
+ case 3: result += "rd"; break;
170
+ default: result += "th"; break;
171
+ }
172
+ }
173
+ /*
174
+ if(( d % 10) == 1 )
175
+ result += "st";
176
+ else if(( d % 10) == 2 )
177
+ result += "nd";
178
+ else if(( d % 10) == 3 )
179
+ result += "rd";
180
+ else
181
+ result += "th";
182
+ */
183
+ }
184
+
185
+ else if( thisFmt == "w" ) // Day of week as a number (0=Sun)
186
+ result += theDate.getDay();
187
+
188
+ else if( thisFmt == "ww" ) // Week of the year
189
+ result += parseInt(dayOfYear(theDate)/7, 10) + 1;
190
+
191
+ else if( thisFmt == "m" ) // Month number w/o leading 0
192
+ result += theDate.getMonth() + 1;
193
+
194
+ else if (thisFmt == "mm" ) // Month number with leading 0
195
+ result += padnum2(theDate.getMonth() + 1);
196
+
197
+ else if (thisFmt == "mmm" ) // Month name abbreviated
198
+ result += monthnames[theDate.getMonth()].substr(0,3);
199
+
200
+ else if (thisFmt == "mmmm" ) // Month name full
201
+ result += monthnames[theDate.getMonth()];
202
+
203
+ else if (thisFmt == "q" ) // Quarter of year as number
204
+ result += parseInt(theDate.getMonth()/3) + 1;
205
+
206
+ else if (thisFmt == "qq" ) // Quarter of year as ordinal
207
+ {
208
+ var q = parseInt(theDate.getMonth()/3);
209
+ if( q == 0 )
210
+ result += "1st";
211
+ else if( q == 1 )
212
+ result += "2nd";
213
+ else if( q == 2 )
214
+ result += "3rd";
215
+ else if( q == 3 )
216
+ result += "4th";
217
+ }
218
+
219
+ else if( thisFmt == "y" ) // Day of the year as number
220
+ result += dayOfYear(theDate);
221
+
222
+ else if( thisFmt == "yy" ) // Year as two digits
223
+ result += ("" + theDate.getFullYear()).substr(2,2);
224
+
225
+ else if( thisFmt == "yyyy" ) // Year as four digits
226
+ result += theDate.getFullYear();
227
+
228
+ else if( thisFmt == "h" ) // Hour (1-12) w/o leading 0
229
+ result += ((theDate.getHours() + 12 - 1) % 12) + 1;
230
+
231
+ else if (thisFmt == "hh" ) // Hour (1-12) with leading 0
232
+ result += padnum2(((theDate.getHours() + 12 - 1) % 12) + 1);
233
+
234
+ else if( thisFmt == "h24" ) // Hour (0-23) w/o leading 0
235
+ result += theDate.getHours();
236
+
237
+ else if (thisFmt == "hh24" ) // Hour (0-23) with leading 0
238
+ result += padnum2(theDate.getHours());
239
+
240
+ else if( thisFmt == "n" ) // Minute w/o leading 0
241
+ result += theDate.getMinutes();
242
+
243
+ else if (thisFmt == "nn" ) // Minute with leading 0
244
+ result += padnum2(theDate.getMinutes());
245
+
246
+ else if( thisFmt == "s" ) // Seconds w/o leading 0
247
+ result += theDate.getSeconds();
248
+
249
+ else if ( thisFmt == "ss" ) // Seconds with leading 0
250
+ result += padnum2(theDate.getSeconds());
251
+
252
+ else if ( thisFmt == "AM/PM" ) // AM/PM capitalized
253
+ result += theDate.getHours() < 12 ? "AM" : "PM";
254
+
255
+ else if ( thisFmt == "am/pm" ) // am/pm lowercase
256
+ result += theDate.getHours() < 12 ? "am" : "pm";
257
+
258
+ else if ( thisFmt == "A/P" ) // A/P capitalized
259
+ result += theDate.getHours() < 12 ? "A" : "P";
260
+
261
+ else if ( thisFmt == "a/p" ) // a/p lowercase
262
+ result += theDate.getHours() < 12 ? "a" : "p";
263
+
264
+ else if ( thisFmt == "tz") // Timezone as hours behind Greenwich
265
+ result += theDate.getTimezoneOffset();
266
+
267
+ else if ( thisFmt == "tzn") // Timezone as name
268
+ {
269
+ mon = "" + theDate;
270
+ result += mon.substr(20, mon.length - 25);
271
+ }
272
+
273
+ else
274
+ return ERR_UNKNOWN;
275
+ }
276
+ else
277
+ result += c;
278
+
279
+ ++fmtIndex;
280
+ } // while
281
+
282
+ return result;
283
+ }