From decd129a4d366e47fceafa4d2be374dd36321713 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Sun, 2 Oct 2016 14:12:14 -0700 Subject: [PATCH] refactor(facade): remove DateWrapper (#12027) --- modules/@angular/benchpress/src/common_options.ts | 4 +--- .../benchpress/src/reporter/json_file_reporter.ts | 5 ++--- .../test/reporter/console_reporter_spec.ts | 4 ++-- .../test/reporter/json_file_reporter_spec.ts | 6 +++--- .../benchpress/test/reporter/multi_reporter_spec.ts | 8 +++----- modules/@angular/benchpress/test/sampler_spec.ts | 6 +++--- .../validator/regression_slope_validator_spec.ts | 3 +-- .../test/validator/size_validator_spec.ts | 3 +-- .../@angular/common/test/pipes/date_pipe_spec.ts | 4 +--- modules/@angular/facade/src/lang.ts | 13 ------------- .../src/web_workers/shared/client_message_broker.ts | 4 ++-- .../src/old/compiler/compiler_benchmark.ts | 6 +++--- modules/playground/src/routing/app/inbox-app.ts | 7 ++----- 13 files changed, 24 insertions(+), 49 deletions(-) diff --git a/modules/@angular/benchpress/src/common_options.ts b/modules/@angular/benchpress/src/common_options.ts index 7dc5b72730..255862e629 100644 --- a/modules/@angular/benchpress/src/common_options.ts +++ b/modules/@angular/benchpress/src/common_options.ts @@ -9,8 +9,6 @@ import {OpaqueToken} from '@angular/core'; import * as fs from 'fs'; -import {DateWrapper} from './facade/lang'; - export class Options { static SAMPLE_ID = new OpaqueToken('Options.sampleId'); static DEFAULT_DESCRIPTION = new OpaqueToken('Options.defaultDescription'); @@ -34,7 +32,7 @@ export class Options { {provide: Options.FORCE_GC, useValue: false}, {provide: Options.PREPARE, useValue: Options.NO_PREPARE}, {provide: Options.MICRO_METRICS, useValue: {}}, {provide: Options.USER_METRICS, useValue: {}}, - {provide: Options.NOW, useValue: () => DateWrapper.now()}, + {provide: Options.NOW, useValue: () => new Date()}, {provide: Options.RECEIVED_DATA, useValue: false}, {provide: Options.REQUEST_COUNT, useValue: false}, {provide: Options.CAPTURE_FRAMES, useValue: false}, diff --git a/modules/@angular/benchpress/src/reporter/json_file_reporter.ts b/modules/@angular/benchpress/src/reporter/json_file_reporter.ts index db64677881..67c28a592b 100644 --- a/modules/@angular/benchpress/src/reporter/json_file_reporter.ts +++ b/modules/@angular/benchpress/src/reporter/json_file_reporter.ts @@ -9,7 +9,7 @@ import {Inject, Injectable, OpaqueToken} from '@angular/core'; import {Options} from '../common_options'; -import {DateWrapper, Json} from '../facade/lang'; +import {Json} from '../facade/lang'; import {MeasureValues} from '../measure_values'; import {Reporter} from '../reporter'; import {SampleDescription} from '../sample_description'; @@ -45,8 +45,7 @@ export class JsonFileReporter extends Reporter { 'completeSample': completeSample, 'validSample': validSample, }); - var filePath = - `${this._path}/${this._description.id}_${DateWrapper.toMillis(this._now())}.json`; + var filePath = `${this._path}/${this._description.id}_${this._now().getTime()}.json`; return this._writeFile(filePath, content); } } diff --git a/modules/@angular/benchpress/test/reporter/console_reporter_spec.ts b/modules/@angular/benchpress/test/reporter/console_reporter_spec.ts index c3b1a093fa..6420ba30c6 100644 --- a/modules/@angular/benchpress/test/reporter/console_reporter_spec.ts +++ b/modules/@angular/benchpress/test/reporter/console_reporter_spec.ts @@ -10,7 +10,7 @@ import {Provider} from '@angular/core'; import {describe, expect, it} from '@angular/core/testing/testing_internal'; import {ConsoleReporter, MeasureValues, ReflectiveInjector, SampleDescription} from '../../index'; -import {DateWrapper, isBlank, isPresent} from '../../src/facade/lang'; +import {isBlank, isPresent} from '../../src/facade/lang'; export function main() { describe('console reporter', () => { @@ -90,5 +90,5 @@ export function main() { } function mv(runIndex: number, time: number, values: {[key: string]: number}) { - return new MeasureValues(runIndex, DateWrapper.fromMillis(time), values); + return new MeasureValues(runIndex, new Date(time), values); } diff --git a/modules/@angular/benchpress/test/reporter/json_file_reporter_spec.ts b/modules/@angular/benchpress/test/reporter/json_file_reporter_spec.ts index f5ce8027d9..3036f6c33e 100644 --- a/modules/@angular/benchpress/test/reporter/json_file_reporter_spec.ts +++ b/modules/@angular/benchpress/test/reporter/json_file_reporter_spec.ts @@ -9,7 +9,7 @@ import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal'; import {JsonFileReporter, MeasureValues, Options, ReflectiveInjector, SampleDescription} from '../../index'; -import {DateWrapper, Json, isPresent} from '../../src/facade/lang'; +import {Json, isPresent} from '../../src/facade/lang'; export function main() { describe('file reporter', () => { @@ -27,7 +27,7 @@ export function main() { useValue: new SampleDescription(sampleId, descriptions, metrics) }, {provide: JsonFileReporter.PATH, useValue: path}, - {provide: Options.NOW, useValue: () => DateWrapper.fromMillis(1234)}, { + {provide: Options.NOW, useValue: () => new Date(1234)}, { provide: Options.WRITE_FILE, useValue: (filename: string, content: string) => { loggedFile = {'filename': filename, 'content': content}; @@ -77,5 +77,5 @@ export function main() { } function mv(runIndex: number, time: number, values: {[key: string]: number}) { - return new MeasureValues(runIndex, DateWrapper.fromMillis(time), values); + return new MeasureValues(runIndex, new Date(time), values); } diff --git a/modules/@angular/benchpress/test/reporter/multi_reporter_spec.ts b/modules/@angular/benchpress/test/reporter/multi_reporter_spec.ts index 89b0c371f4..c880fc6393 100644 --- a/modules/@angular/benchpress/test/reporter/multi_reporter_spec.ts +++ b/modules/@angular/benchpress/test/reporter/multi_reporter_spec.ts @@ -9,7 +9,6 @@ import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal'; import {MeasureValues, MultiReporter, ReflectiveInjector, Reporter} from '../../index'; -import {DateWrapper} from '../../src/facade/lang'; export function main() { function createReporters(ids: any[]) { @@ -26,7 +25,7 @@ export function main() { it('should reportMeasureValues to all', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - var mv = new MeasureValues(0, DateWrapper.now(), {}); + var mv = new MeasureValues(0, new Date(), {}); createReporters(['m1', 'm2']).then((r) => r.reportMeasureValues(mv)).then((values) => { expect(values).toEqual([{'id': 'm1', 'values': mv}, {'id': 'm2', 'values': mv}]); @@ -35,9 +34,8 @@ export function main() { })); it('should reportSample to call', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - var completeSample = [ - new MeasureValues(0, DateWrapper.now(), {}), new MeasureValues(1, DateWrapper.now(), {}) - ]; + var completeSample = + [new MeasureValues(0, new Date(), {}), new MeasureValues(1, new Date(), {})]; var validSample = [completeSample[1]]; createReporters(['m1', 'm2']) diff --git a/modules/@angular/benchpress/test/sampler_spec.ts b/modules/@angular/benchpress/test/sampler_spec.ts index 345d2865ad..b52f4b2dea 100644 --- a/modules/@angular/benchpress/test/sampler_spec.ts +++ b/modules/@angular/benchpress/test/sampler_spec.ts @@ -9,7 +9,7 @@ import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal'; import {MeasureValues, Metric, Options, ReflectiveInjector, Reporter, Sampler, Validator, WebDriverAdapter} from '../index'; -import {DateWrapper, isBlank, isPresent} from '../src/facade/lang'; +import {isBlank, isPresent} from '../src/facade/lang'; export function main() { var EMPTY_EXECUTE = () => {}; @@ -39,7 +39,7 @@ export function main() { Options.DEFAULT_PROVIDERS, Sampler.PROVIDERS, {provide: Metric, useValue: metric}, {provide: Reporter, useValue: reporter}, {provide: WebDriverAdapter, useValue: driver}, {provide: Options.EXECUTE, useValue: execute}, {provide: Validator, useValue: validator}, - {provide: Options.NOW, useValue: () => DateWrapper.fromMillis(time++)} + {provide: Options.NOW, useValue: () => new Date(time++)} ]; if (isPresent(prepare)) { providers.push({provide: Options.PREPARE, useValue: prepare}); @@ -204,7 +204,7 @@ export function main() { } function mv(runIndex: number, time: number, values: {[key: string]: number}) { - return new MeasureValues(runIndex, DateWrapper.fromMillis(time), values); + return new MeasureValues(runIndex, new Date(time), values); } function createCountingValidator( diff --git a/modules/@angular/benchpress/test/validator/regression_slope_validator_spec.ts b/modules/@angular/benchpress/test/validator/regression_slope_validator_spec.ts index 66e2a262db..9b7be26063 100644 --- a/modules/@angular/benchpress/test/validator/regression_slope_validator_spec.ts +++ b/modules/@angular/benchpress/test/validator/regression_slope_validator_spec.ts @@ -10,7 +10,6 @@ import {describe, expect, it} from '@angular/core/testing/testing_internal'; import {MeasureValues, ReflectiveInjector, RegressionSlopeValidator} from '../../index'; import {ListWrapper} from '../../src/facade/collection'; -import {DateWrapper} from '../../src/facade/lang'; export function main() { describe('regression slope validator', () => { @@ -62,5 +61,5 @@ export function main() { } function mv(runIndex: number, time: number, values: {[key: string]: number}) { - return new MeasureValues(runIndex, DateWrapper.fromMillis(time), values); + return new MeasureValues(runIndex, new Date(time), values); } diff --git a/modules/@angular/benchpress/test/validator/size_validator_spec.ts b/modules/@angular/benchpress/test/validator/size_validator_spec.ts index b75358798b..6cdb21eff8 100644 --- a/modules/@angular/benchpress/test/validator/size_validator_spec.ts +++ b/modules/@angular/benchpress/test/validator/size_validator_spec.ts @@ -10,7 +10,6 @@ import {describe, expect, it} from '@angular/core/testing/testing_internal'; import {MeasureValues, ReflectiveInjector, SizeValidator} from '../../index'; import {ListWrapper} from '../../src/facade/collection'; -import {DateWrapper} from '../../src/facade/lang'; export function main() { describe('size validator', () => { @@ -47,5 +46,5 @@ export function main() { } function mv(runIndex: number, time: number, values: {[key: string]: number}) { - return new MeasureValues(runIndex, DateWrapper.fromMillis(time), values); + return new MeasureValues(runIndex, new Date(time), values); } diff --git a/modules/@angular/common/test/pipes/date_pipe_spec.ts b/modules/@angular/common/test/pipes/date_pipe_spec.ts index 32c88cf203..2667f88e1f 100644 --- a/modules/@angular/common/test/pipes/date_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/date_pipe_spec.ts @@ -11,8 +11,6 @@ import {PipeResolver} from '@angular/compiler/src/pipe_resolver'; import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_internal'; import {browserDetection} from '@angular/platform-browser/testing/browser_util'; -import {DateWrapper} from '../../src/facade/lang'; - export function main() { describe('DatePipe', () => { var date: Date; @@ -27,7 +25,7 @@ export function main() { // Tracking issue: https://github.com/angular/angular/issues/11187 beforeEach(() => { - date = DateWrapper.create(2015, 6, 15, 9, 3, 1); + date = new Date(2015, 5, 15, 9, 3, 1); pipe = new DatePipe('en-US'); }); diff --git a/modules/@angular/facade/src/lang.ts b/modules/@angular/facade/src/lang.ts index 5cc46d0405..982528761f 100644 --- a/modules/@angular/facade/src/lang.ts +++ b/modules/@angular/facade/src/lang.ts @@ -301,19 +301,6 @@ export class Json { } } -export class DateWrapper { - static create( - year: number, month: number = 1, day: number = 1, hour: number = 0, minutes: number = 0, - seconds: number = 0, milliseconds: number = 0): Date { - return new Date(year, month - 1, day, hour, minutes, seconds, milliseconds); - } - static fromISOString(str: string): Date { return new Date(str); } - static fromMillis(ms: number): Date { return new Date(ms); } - static toMillis(date: Date): number { return date.getTime(); } - static now(): Date { return new Date(); } - static toJson(date: Date): string { return date.toJSON(); } -} - export function setValueOnPath(global: any, path: string, value: any) { var parts = path.split('.'); var obj: any = global; diff --git a/modules/@angular/platform-webworker/src/web_workers/shared/client_message_broker.ts b/modules/@angular/platform-webworker/src/web_workers/shared/client_message_broker.ts index f450417d6f..5f8e1bd04b 100644 --- a/modules/@angular/platform-webworker/src/web_workers/shared/client_message_broker.ts +++ b/modules/@angular/platform-webworker/src/web_workers/shared/client_message_broker.ts @@ -9,7 +9,7 @@ import {Injectable, Type} from '@angular/core'; import {EventEmitter} from '../../facade/async'; -import {DateWrapper, StringWrapper, isPresent, print, stringify} from '../../facade/lang'; +import {StringWrapper, isPresent, print, stringify} from '../../facade/lang'; import {MessageBus} from './message_bus'; import {Serializer} from './serializer'; @@ -71,7 +71,7 @@ export class ClientMessageBroker_ extends ClientMessageBroker { } private _generateMessageId(name: string): string { - var time: string = stringify(DateWrapper.toMillis(DateWrapper.now())); + var time: string = stringify(new Date().getTime()); var iteration: number = 0; var id: string = name + time + stringify(iteration); while (isPresent((this as any /** TODO #9100 */)._pending[id])) { diff --git a/modules/benchmarks/src/old/compiler/compiler_benchmark.ts b/modules/benchmarks/src/old/compiler/compiler_benchmark.ts index d0f87ff88a..c5a4bc5f0b 100644 --- a/modules/benchmarks/src/old/compiler/compiler_benchmark.ts +++ b/modules/benchmarks/src/old/compiler/compiler_benchmark.ts @@ -1,6 +1,6 @@ import {PromiseWrapper} from '@angular/facade/src/async'; import {ListWrapper, Map, MapWrapper} from '@angular/facade/src/collection'; -import {DateWrapper, Type, isPresent, print} from '@angular/facade/src/lang'; +import {Type, isPresent, print} from '@angular/facade/src/lang'; import {bootstrap} from '@angular/platform-browser'; import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter'; import {DOM} from '@angular/platform-browser/src/dom/dom_adapter'; @@ -44,10 +44,10 @@ export function main() { function measureWrapper(func, desc) { return function() { - var begin = DateWrapper.now(); + var begin = new Date(); print(`[${desc}] Begin...`); var onSuccess = function(_) { - var elapsedMs = DateWrapper.toMillis(DateWrapper.now()) - DateWrapper.toMillis(begin); + var elapsedMs = new Date().getTime() - begin.getTime(); print(`[${desc}] ...done, took ${elapsedMs} ms`); }; var onError = function(e) { DOM.logError(e); }; diff --git a/modules/playground/src/routing/app/inbox-app.ts b/modules/playground/src/routing/app/inbox-app.ts index e756397cf4..3b0a4055ed 100644 --- a/modules/playground/src/routing/app/inbox-app.ts +++ b/modules/playground/src/routing/app/inbox-app.ts @@ -8,7 +8,7 @@ import {Component, Injectable} from '@angular/core'; -import {DateWrapper, isPresent} from '@angular/core/src/facade/lang'; +import {isPresent} from '@angular/core/src/facade/lang'; import {ActivatedRoute, Router} from '@angular/router'; import * as db from './data'; @@ -102,10 +102,7 @@ export class InboxCmp { if (sortEmailsByDate) { this.items.sort( (a: InboxRecord, b: InboxRecord) => - DateWrapper.toMillis(DateWrapper.fromISOString(a.date)) < - DateWrapper.toMillis(DateWrapper.fromISOString(b.date)) ? - -1 : - 1); + new Date(a.date).getTime() < new Date(b.date).getTime() ? -1 : 1); } }); });