~ubuntu-branches/ubuntu/saucy/whoopsie-daisy/saucy

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/3.4.1/docs/datatype/datatype-dateformat.html

  • Committer: Package Import Robot
  • Author(s): Evan Dandrea
  • Date: 2012-04-18 13:04:36 UTC
  • Revision ID: package-import@ubuntu.com-20120418130436-vmt93p8fds516lws
Tags: 0.1.32
Fix failing tests on powerpc and ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html>
2
 
<html lang="en">
3
 
<head>
4
 
    <meta charset="utf-8">
5
 
    <title>Example: DataType.Date.format()</title>
6
 
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
 
    <link rel="stylesheet" href="../assets/css/main.css">
8
 
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
 
    <script src="../../build/yui/yui-min.js"></script>
10
 
</head>
11
 
<body>
12
 
 
13
 
<div id="doc">
14
 
    <h1>Example: DataType.Date.format()</h1>
15
 
 
16
 
    
17
 
 
18
 
    <div class="yui3-g">
19
 
        <div id="main" class="yui3-u">
20
 
            <div class="content"><style scoped>
21
 
/* custom styles for this example */
22
 
#demo .output {margin-bottom:1em; padding:10px; border:1px solid #D9D9D9;}
23
 
</style>
24
 
 
25
 
<div class="intro">
26
 
    <p>The Date module of the DataType Utility allows you to format a JavaScript Date object into a string with <code>strftime</code> syntax. This method allows you to specify any tokenized HTML value as the format. However, in this example the formatted output will be escaped for security.</p>
27
 
 
28
 
    <p><strong>NOTE:</strong> As of 3.1.0, the formatting patterns used by DateType.Date can be driven by external language resource bundles as described in the <a href="datatype-dateformat-lang.html">"Formatting Dates Using Language Resource Bundles" Example</a>. This examples currently uses the 3.0.0 <code>dateFormat</code> and <code>locale</code> instance configuration support which have been deprecated.</p>
29
 
</div>
30
 
 
31
 
<div class="example yui3-skin-sam">
32
 
    <form id="demo">
33
 
    <fieldset>
34
 
        <label for="demo_format">Format (optional):</label>
35
 
        <input type="text" id="demo_format" value="%r">
36
 
        <label for="demo_locale">Locale (optional):</label>
37
 
        <input type="text" id="demo_locale" value="en-GB">
38
 
        <input type="button" id="demo_btn" value="Format current date =>">
39
 
        <div id="demo_output" class="output">&nbsp;</div>
40
 
    </fieldset>
41
 
</form>
42
 
 
43
 
 
44
 
 
45
 
<script>
46
 
YUI().use("node", "datatype-date", "escape", function (Y) {
47
 
    Y.on("click", function(e){
48
 
        var date = new Date(),
49
 
            output = Y.DataType.Date.format(date, {format:Y.one("#demo_format").get("value"), locale:Y.one("#demo_locale").get("value")});
50
 
 
51
 
        if(output === "") {
52
 
            output += "(Invalid input)"
53
 
        }
54
 
        Y.one("#demo_output").setContent(Y.Escape.html(output));
55
 
    }, "#demo_btn");
56
 
});
57
 
</script>
58
 
 
59
 
</div>
60
 
 
61
 
<p>To convert a data value to a date, simply call the <code>parse()</code> function of the DataType.Date class:</p>
62
 
 
63
 
<pre class="code prettyprint">YUI().use(&quot;datatype-date&quot;, function(Y) {
64
 
    var date = Y.DataType.Date.parse(&quot;Jan 7, 2003&quot;);
65
 
    &#x2F;&#x2F; date is a JavaScript Date object
66
 
});</pre>
67
 
 
68
 
 
69
 
<p>Under the hood, the data value is converted to a date via the <code>Date()</code> constructor:</p>
70
 
 
71
 
<pre class="code prettyprint">YUI().use(&quot;datatype-date&quot;, function(Y) {
72
 
    &#x2F;&#x2F; These all return dates
73
 
    var date = Y.DataType.Date.parse(&quot;December 17, 1995 03:24:00&quot;);
74
 
 
75
 
    date = Y.DataType.Date.parse(1995,11,17);
76
 
 
77
 
    date = Y.DataType.Date.parse(1995,11,17,3,24,0);
78
 
 
79
 
    date = Y.DataType.Date.parse(948548583);
80
 
});</pre>
81
 
 
82
 
</div>
83
 
        </div>
84
 
 
85
 
        <div id="sidebar" class="yui3-u">
86
 
            
87
 
 
88
 
            
89
 
                <div class="sidebox">
90
 
                    <div class="hd">
91
 
                        <h2 class="no-toc">Examples</h2>
92
 
                    </div>
93
 
 
94
 
                    <div class="bd">
95
 
                        <ul class="examples">
96
 
                            
97
 
                                
98
 
                                    <li data-description="Formatting dates into strings.">
99
 
                                        <a href="datatype-dateformat.html">DataType.Date.format()</a>
100
 
                                    </li>
101
 
                                
102
 
                            
103
 
                                
104
 
                                    <li data-description="Formatting dates into strings using pre-packaged language resource bundles.">
105
 
                                        <a href="datatype-dateformat-lang.html">Formatting Dates Using Language Resource Bundles</a>
106
 
                                    </li>
107
 
                                
108
 
                            
109
 
                                
110
 
                                    <li data-description="Parsing data into dates.">
111
 
                                        <a href="datatype-dateparse.html">DataType.Date.parse()</a>
112
 
                                    </li>
113
 
                                
114
 
                            
115
 
                                
116
 
                                    <li data-description="Formatting numbers into strings.">
117
 
                                        <a href="datatype-numberformat.html">DataType.Number.format()</a>
118
 
                                    </li>
119
 
                                
120
 
                            
121
 
                                
122
 
                                    <li data-description="Parsing data into numbers.">
123
 
                                        <a href="datatype-numberparse.html">DataType.Number.parse()</a>
124
 
                                    </li>
125
 
                                
126
 
                            
127
 
                                
128
 
                                    <li data-description="Formatting XML documents into strings.">
129
 
                                        <a href="datatype-xmlformat.html">DataType.XML.format()</a>
130
 
                                    </li>
131
 
                                
132
 
                            
133
 
                                
134
 
                                    <li data-description="Parsing strings into XML documents.">
135
 
                                        <a href="datatype-xmlparse.html">DataType.XML.parse()</a>
136
 
                                    </li>
137
 
                                
138
 
                            
139
 
                        </ul>
140
 
                    </div>
141
 
                </div>
142
 
            
143
 
 
144
 
            
145
 
        </div>
146
 
    </div>
147
 
</div>
148
 
 
149
 
<script src="../assets/vendor/prettify/prettify-min.js"></script>
150
 
<script>prettyPrint();</script>
151
 
 
152
 
</body>
153
 
</html>