Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: corelib/src/date.dart

Issue 10384149: Refactor Date. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add comparison operators. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | corelib/src/time_zone.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Dart core library. 5 // Dart core library.
6 6
7 /** 7 /**
8 * Returns the local time-zone as defined in the official zone.tab file.
9 *
10 * Examples: [:"Europe/Andorra":], [:"America/Los_Angeles":] or
11 * [:"Europe/Paris":].
12 *
13 * If the underlying implementation is unable to get the correct timezone
14 * returns the offset to UTC. Examples: [:"GMT+03":], [:"GMT-02":], or
15 * [:"GTM+04:30":].
16 */
17 String get localTimeZone() => DateImplementation.localTimeZone();
18 /** Returns the current local time-zone's offset to UTC. */
19 int get timeZoneOffsetInMinutes()
Sean Eagan 2012/05/14 14:43:51 this should return a Duration instead of hard code
floitsch 2012/05/14 15:01:16 good catch.
20 => DateImplementation.timeZoneOffsetInMinutes();
21 /** Returns true if the local time-zone is currently in summer-savings mode. */
22 bool get summerTimeSavingsIsActive()
Sean Eagan 2012/05/14 14:43:51 it looks like this tries to combine the terms 'day
floitsch 2012/05/14 15:01:16 my mistake. I wanted to write DaylightSavingsTimeI
Sean Eagan 2012/05/14 16:05:16 oh, I thought this was an instance method on Date.
floitsch 2012/05/14 16:12:11 Yes and no. It is both a property of a specific Da
23 => DateImplementation.summerTimeSavingsIsActive();
24
25 /**
8 * Date is the public interface to a point in time. 26 * Date is the public interface to a point in time.
9 */ 27 */
10 interface Date extends Comparable default DateImplementation { 28 interface Date extends Comparable, Hashable default DateImplementation {
11 // Weekday constants that are returned by [weekday] method: 29 // Weekday constants that are returned by [weekday] method:
12 static final int MON = 0; 30 static final int MON = 0;
13 static final int TUE = 1; 31 static final int TUE = 1;
14 static final int WED = 2; 32 static final int WED = 2;
15 static final int THU = 3; 33 static final int THU = 3;
16 static final int FRI = 4; 34 static final int FRI = 4;
17 static final int SAT = 5; 35 static final int SAT = 5;
18 static final int SUN = 6; 36 static final int SUN = 6;
19 static final int DAYS_IN_WEEK = 7; 37 static final int DAYS_IN_WEEK = 7;
20 38
21 // Month constants that are returned by the [month] getter. 39 // Month constants that are returned by the [month] getter.
22 static final int JAN = 1; 40 static final int JAN = 1;
23 static final int FEB = 2; 41 static final int FEB = 2;
24 static final int MAR = 3; 42 static final int MAR = 3;
25 static final int APR = 4; 43 static final int APR = 4;
26 static final int MAY = 5; 44 static final int MAY = 5;
27 static final int JUN = 6; 45 static final int JUN = 6;
28 static final int JUL = 7; 46 static final int JUL = 7;
29 static final int AUG = 8; 47 static final int AUG = 8;
30 static final int SEP = 9; 48 static final int SEP = 9;
31 static final int OCT = 10; 49 static final int OCT = 10;
32 static final int NOV = 11; 50 static final int NOV = 11;
33 static final int DEC = 12; 51 static final int DEC = 12;
34 52
35 /** 53 /**
36 * Constructs a [Date] instance based on the individual parts, in the 54 * Constructs a [Date] instance based on the individual parts, in the
37 * local time-zone. 55 * local time-zone.
38 */ 56 */
39 Date(int year, 57 Date(int year,
40 int month, 58 [int month = 1,
41 int day, 59 int day = 1,
42 int hours, 60 int hours = 0,
43 int minutes, 61 int minutes = 0,
44 int seconds, 62 int seconds = 0,
45 int milliseconds); 63 int milliseconds = 0]);
46 64
47 /** 65 /**
48 * Constructs a [Date] instance based on the individual parts. 66 * Constructs a new [Date] instance with current date time value in the
49 * [timeZone] may not be [:null:]. 67 * local time-zone.
50 */
51 Date.withTimeZone(int year,
52 int month,
53 int day,
54 int hours,
55 int minutes,
56 int seconds,
57 int milliseconds,
58 TimeZone timeZone);
59
60 /**
61 * Constructs a new [Date] instance with current date time value.
62 * The [timeZone] of this instance is set to the local time-zone.
63 */ 68 */
64 Date.now(); 69 Date.now();
65 70
66 /** 71 /**
67 * Constructs a new [Date] instance based on [formattedString]. 72 * Constructs a new [Date] instance based on [formattedString].
68 */ 73 */
69 Date.fromString(String formattedString); 74 Date.fromString(String formattedString);
70 75
71 /** 76 /**
72 * Constructs a new [Date] instance with the given time zone. The given 77 * Constructs a new [Date] instance in the local time-zone.
73 * [timeZone] must not be [:null:].
74 * 78 *
75 * This constructor is the only one that doesn't need to be computations and 79 * This constructor is the only one that doesn't need to be computations and
76 * which can therefore be [:const:]. 80 * which can therefore be [:const:].
77 * 81 *
78 * The constructed [Date] represents 1970-01-01T00:00:00Z + [value]ms in 82 * The constructed [Date] represents 1970-01-01T00:00:00Z + [value]ms in
79 * the given [timeZone]. 83 * the local time-zone.
80 */ 84 */
81 const Date.fromEpoch(int value, TimeZone timeZone); 85 const Date.fromEpoch(int value);
82 86
83 /** 87 bool operator <(Date other);
84 * Returns a new [Date] in the given [targetTimeZone] time zone. The 88 bool operator <=(Date other);
85 * [value] of the new instance is equal to [:this.value:]. 89 bool operator >=(Date other);
86 * 90 bool operator >(Date other);
87 * This call is equivalent to
88 * [:new Date.fromEpoch(this.value, targetTimeZone):].
89 */
90 Date changeTimeZone(TimeZone targetTimeZone);
91 91
92 /** 92 /**
93 * Returns the year. 93 * Returns the year.
94 */ 94 */
95 int get year(); 95 int get year();
96 96
97 /** 97 /**
98 * Returns the month in the year [1..12]. 98 * Returns the month in the year [1..12].
99 */ 99 */
100 int get month(); 100 int get month();
(...skipping 24 matching lines...) Expand all
125 int get milliseconds(); 125 int get milliseconds();
126 126
127 /** 127 /**
128 * Returns the week day [MON..SUN] 128 * Returns the week day [MON..SUN]
129 */ 129 */
130 int get weekday(); 130 int get weekday();
131 131
132 /** 132 /**
133 * Returns milliseconds from 1970-01-01T00:00:00Z (UTC). 133 * Returns milliseconds from 1970-01-01T00:00:00Z (UTC).
134 * 134 *
135 * Note that this value is independent of [timeZone]. 135 * Note that this value is independent of any time-zone.
136 */ 136 */
137 final int value; 137 final int value;
138 138
139 /** 139 /**
140 * Returns the timeZone of this instance. 140 * Returns a human readable string for this instance. The returned string
141 */ 141 * is constructed in the local time-zone and does not have any time-zone
142 final TimeZone timeZone; 142 * indication. Example: [:2012-05-14 14:20:25.442:]
143
144 /**
145 * Returns true if this [Date] is set to local time.
146 */
147 bool isLocalTime();
148
149 /**
150 * Returns true if this [Date] is set to UTC time.
151 * This is equivalent to [:this.timeZone.isUtc():].
152 */
153 bool isUtc();
154
155 /**
156 * Returns a human readable string for this instance.
157 * The returned string is constructed for the [timeZone] of this instance.
158 */ 143 */
159 String toString(); 144 String toString();
160 145
161 /** 146 /**
147 * Returns a human readable string for this instance in UTC time-zone.
148 * Example: [:2012-05-14 12:21:04.989Z:]
floitsch 2012/05/14 15:01:16 Should we instead return a valid ISO 8601? It woul
149 */
150 String toUTCString();
Sean Eagan 2012/05/14 14:43:51 toUtcString per the Dart style guide
floitsch 2012/05/14 15:01:16 Done.
151
152 /**
162 * Returns a new [Date] with the [duration] added to this instance. 153 * Returns a new [Date] with the [duration] added to this instance.
163 */ 154 */
164 Date add(Duration duration); 155 Date add(Duration duration);
165 156
166 /** 157 /**
167 * Returns a new [Date] with the [duration] subtracted from this instance. 158 * Returns a new [Date] with the [duration] subtracted from this instance.
168 */ 159 */
169 Date subtract(Duration duration); 160 Date subtract(Duration duration);
170 161
171 /** 162 /**
172 * Returns a [Duration] with the difference of [:this:] and [other]. 163 * Returns a [Duration] with the difference of [:this:] and [other].
173 */ 164 */
174 Duration difference(Date other); 165 Duration difference(Date other);
175 } 166 }
OLDNEW
« no previous file with comments | « no previous file | corelib/src/time_zone.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698