const dateExpected = items.content.map(v => v.pubDate).map(v => datePipe.transform(v, 'dd/MM/yyyy à HH:mm'));
Example #2
0
 it('should support int', () => { expect(() => pipe.transform(123456789)).not.toThrow(); });
Example #3
0
 () => { expect(() => pipe.transform('2015-06-15T21:43:11Z')).not.toThrow(); });
Example #4
0
 it('should format with pattern aliases', () => {
   if (!browserDetection.isOldChrome) {
     // IE and Edge do not add a coma after the year in these 2 cases
     if ((browserDetection.isEdge || browserDetection.isIE) &&
         browserDetection.supportsNativeIntlApi) {
       expect(pipe.transform(date, 'medium')).toEqual('Jun 15, 2015 9:03:01 AM');
       expect(pipe.transform(date, 'short')).toEqual('6/15/2015 9:03 AM');
     } else {
       expect(pipe.transform(date, 'medium')).toEqual('Jun 15, 2015, 9:03:01 AM');
       expect(pipe.transform(date, 'short')).toEqual('6/15/2015, 9:03 AM');
     }
   }
   expect(pipe.transform(date, 'MM/dd/yyyy')).toEqual('06/15/2015');
   expect(pipe.transform(date, 'fullDate')).toEqual('Monday, June 15, 2015');
   expect(pipe.transform(date, 'longDate')).toEqual('June 15, 2015');
   expect(pipe.transform(date, 'mediumDate')).toEqual('Jun 15, 2015');
   expect(pipe.transform(date, 'shortDate')).toEqual('6/15/2015');
   if (!browserDetection.isOldChrome) {
     expect(pipe.transform(date, 'mediumTime')).toEqual('9:03:01 AM');
     expect(pipe.transform(date, 'shortTime')).toEqual('9:03 AM');
   }
 });
Example #5
0
  describe('DatePipe', () => {
    var date: Date;
    var pipe: DatePipe;

    // TODO: reactivate the disabled expectations once emulators are fixed in SauceLabs
    // In some old versions of Chrome in Android emulators, time formatting returns dates in the
    // timezone of the VM host,
    // instead of the device timezone. Same symptoms as
    // https://bugs.chromium.org/p/chromium/issues/detail?id=406382
    // This happens locally and in SauceLabs, so some checks are disabled to avoid failures.
    // Tracking issue: https://github.com/angular/angular/issues/11187

    beforeEach(() => {
      date = new Date(2015, 5, 15, 9, 3, 1);
      pipe = new DatePipe('en-US');
    });

    it('should be marked as pure',
       () => { expect(new PipeResolver().resolve(DatePipe).pure).toEqual(true); });

    describe('supports', () => {
      it('should support date', () => { expect(() => pipe.transform(date)).not.toThrow(); });
      it('should support int', () => { expect(() => pipe.transform(123456789)).not.toThrow(); });
      it('should support numeric strings',
         () => { expect(() => pipe.transform('123456789')).not.toThrow(); });

      it('should support decimal strings',
         () => { expect(() => pipe.transform('123456789.11')).not.toThrow(); });

      it('should support ISO string',
         () => { expect(() => pipe.transform('2015-06-15T21:43:11Z')).not.toThrow(); });

      it('should not support other objects', () => {
        expect(() => pipe.transform({})).toThrow();
        expect(() => pipe.transform('')).toThrow();
      });
    });

    describe('transform', () => {
      it('should format each component correctly', () => {
        expect(pipe.transform(date, 'y')).toEqual('2015');
        expect(pipe.transform(date, 'yy')).toEqual('15');
        expect(pipe.transform(date, 'M')).toEqual('6');
        expect(pipe.transform(date, 'MM')).toEqual('06');
        expect(pipe.transform(date, 'MMM')).toEqual('Jun');
        expect(pipe.transform(date, 'MMMM')).toEqual('June');
        expect(pipe.transform(date, 'd')).toEqual('15');
        expect(pipe.transform(date, 'EEE')).toEqual('Mon');
        expect(pipe.transform(date, 'EEEE')).toEqual('Monday');
        if (!browserDetection.isOldChrome) {
          expect(pipe.transform(date, 'h')).toEqual('9');
          expect(pipe.transform(date, 'hh')).toEqual('09');
          expect(pipe.transform(date, 'j')).toEqual('9 AM');
        }
        // IE and Edge can't format a date to minutes and seconds without hours
        if (!browserDetection.isEdge && !browserDetection.isIE ||
            !browserDetection.supportsNativeIntlApi) {
          if (!browserDetection.isOldChrome) {
            expect(pipe.transform(date, 'HH')).toEqual('09');
          }

          expect(pipe.transform(date, 'E')).toEqual('M');
          expect(pipe.transform(date, 'L')).toEqual('J');
          expect(pipe.transform(date, 'm')).toEqual('3');
          expect(pipe.transform(date, 's')).toEqual('1');
          expect(pipe.transform(date, 'mm')).toEqual('03');
          expect(pipe.transform(date, 'ss')).toEqual('01');
        }
        expect(pipe.transform(date, 'Z')).toBeDefined();
      });

      it('should format common multi component patterns', () => {
        expect(pipe.transform(date, 'EEE, M/d/y')).toEqual('Mon, 6/15/2015');
        expect(pipe.transform(date, 'EEE, M/d')).toEqual('Mon, 6/15');
        expect(pipe.transform(date, 'MMM d')).toEqual('Jun 15');
        expect(pipe.transform(date, 'dd/MM/yyyy')).toEqual('15/06/2015');
        expect(pipe.transform(date, 'MM/dd/yyyy')).toEqual('06/15/2015');
        expect(pipe.transform(date, 'yMEEEd')).toEqual('20156Mon15');
        expect(pipe.transform(date, 'MEEEd')).toEqual('6Mon15');
        expect(pipe.transform(date, 'MMMd')).toEqual('Jun15');
        expect(pipe.transform(date, 'yMMMMEEEEd')).toEqual('Monday, June 15, 2015');
        // IE and Edge can't format a date to minutes and seconds without hours
        if (!browserDetection.isEdge && !browserDetection.isIE ||
            !browserDetection.supportsNativeIntlApi) {
          expect(pipe.transform(date, 'ms')).toEqual('31');
        }
        if (!browserDetection.isOldChrome) {
          expect(pipe.transform(date, 'jm')).toEqual('9:03 AM');
        }
      });

      it('should format with pattern aliases', () => {
        if (!browserDetection.isOldChrome) {
          // IE and Edge do not add a coma after the year in these 2 cases
          if ((browserDetection.isEdge || browserDetection.isIE) &&
              browserDetection.supportsNativeIntlApi) {
            expect(pipe.transform(date, 'medium')).toEqual('Jun 15, 2015 9:03:01 AM');
            expect(pipe.transform(date, 'short')).toEqual('6/15/2015 9:03 AM');
          } else {
            expect(pipe.transform(date, 'medium')).toEqual('Jun 15, 2015, 9:03:01 AM');
            expect(pipe.transform(date, 'short')).toEqual('6/15/2015, 9:03 AM');
          }
        }
        expect(pipe.transform(date, 'MM/dd/yyyy')).toEqual('06/15/2015');
        expect(pipe.transform(date, 'fullDate')).toEqual('Monday, June 15, 2015');
        expect(pipe.transform(date, 'longDate')).toEqual('June 15, 2015');
        expect(pipe.transform(date, 'mediumDate')).toEqual('Jun 15, 2015');
        expect(pipe.transform(date, 'shortDate')).toEqual('6/15/2015');
        if (!browserDetection.isOldChrome) {
          expect(pipe.transform(date, 'mediumTime')).toEqual('9:03:01 AM');
          expect(pipe.transform(date, 'shortTime')).toEqual('9:03 AM');
        }
      });

      it('should remove bidi control characters',
         () => { expect(pipe.transform(date, 'MM/dd/yyyy').length).toEqual(10); });
    });
  });
Example #6
0
 it('should return null for empty string', () => expect(pipe.transform('')).toEqual(null));
Example #7
0
 () => { expect(() => pipe.transform(isoStringWithoutTime)).not.toThrow(); });
Example #8
0
      it('should format each component correctly', () => {
        expect(pipe.transform(date, 'y')).toEqual('2015');
        expect(pipe.transform(date, 'yy')).toEqual('15');
        expect(pipe.transform(date, 'M')).toEqual('6');
        expect(pipe.transform(date, 'MM')).toEqual('06');
        expect(pipe.transform(date, 'MMM')).toEqual('Jun');
        expect(pipe.transform(date, 'MMMM')).toEqual('June');
        expect(pipe.transform(date, 'd')).toEqual('15');
        expect(pipe.transform(date, 'EEE')).toEqual('Mon');
        expect(pipe.transform(date, 'EEEE')).toEqual('Monday');
        if (!browserDetection.isOldChrome) {
          expect(pipe.transform(date, 'h')).toEqual('9');
          expect(pipe.transform(date, 'hh')).toEqual('09');
          expect(pipe.transform(date, 'j')).toEqual('9 AM');
        }
        // IE and Edge can't format a date to minutes and seconds without hours
        if (!browserDetection.isEdge && !browserDetection.isIE ||
            !browserDetection.supportsNativeIntlApi) {
          if (!browserDetection.isOldChrome) {
            expect(pipe.transform(date, 'HH')).toEqual('09');
          }

          expect(pipe.transform(date, 'E')).toEqual('M');
          expect(pipe.transform(date, 'L')).toEqual('J');
          expect(pipe.transform(date, 'm')).toEqual('3');
          expect(pipe.transform(date, 's')).toEqual('1');
          expect(pipe.transform(date, 'mm')).toEqual('03');
          expect(pipe.transform(date, 'ss')).toEqual('01');
        }
        expect(pipe.transform(date, 'Z')).toBeDefined();
      });
Example #9
0
 it('should format common multi component patterns', () => {
   expect(pipe.transform(date, 'EEE, M/d/y')).toEqual('Mon, 6/15/2015');
   expect(pipe.transform(date, 'EEE, M/d')).toEqual('Mon, 6/15');
   expect(pipe.transform(date, 'MMM d')).toEqual('Jun 15');
   expect(pipe.transform(date, 'dd/MM/yyyy')).toEqual('15/06/2015');
   expect(pipe.transform(date, 'MM/dd/yyyy')).toEqual('06/15/2015');
   expect(pipe.transform(date, 'yMEEEd')).toEqual('20156Mon15');
   expect(pipe.transform(date, 'MEEEd')).toEqual('6Mon15');
   expect(pipe.transform(date, 'MMMd')).toEqual('Jun15');
   expect(pipe.transform(date, 'yMMMMEEEEd')).toEqual('Monday, June 15, 2015');
   // IE and Edge can't format a date to minutes and seconds without hours
   if (!browserDetection.isEdge && !browserDetection.isIE ||
       !browserDetection.supportsNativeIntlApi) {
     expect(pipe.transform(date, 'ms')).toEqual('31');
   }
   if (!browserDetection.isOldChrome) {
     expect(pipe.transform(date, 'jm')).toEqual('9:03 AM');
   }
 });
Example #10
0
 () => expect(pipe.transform('2017-01-11T09:25:14.014-0500')).toEqual('Jan 11, 2017'));
Example #11
0
      it('should format each component correctly', () => {
        const dateFixtures: any = {
          'y': '2015',
          'yy': '15',
          'M': '6',
          'MM': '06',
          'MMM': 'Jun',
          'MMMM': 'June',
          'd': '15',
          'dd': '15',
          'EEE': 'Mon',
          'EEEE': 'Monday'
        };

        const isoStringWithoutTimeFixtures: any = {
          'y': '2015',
          'yy': '15',
          'M': '1',
          'MM': '01',
          'MMM': 'Jan',
          'MMMM': 'January',
          'd': '1',
          'dd': '01',
          'EEE': 'Thu',
          'EEEE': 'Thursday'
        };

        if (!browserDetection.isOldChrome) {
          dateFixtures['h'] = '9';
          dateFixtures['hh'] = '09';
          dateFixtures['j'] = '9 AM';
          isoStringWithoutTimeFixtures['h'] = '12';
          isoStringWithoutTimeFixtures['hh'] = '12';
          isoStringWithoutTimeFixtures['j'] = '12 AM';
        }

        // IE and Edge can't format a date to minutes and seconds without hours
        if (!browserDetection.isEdge && !browserDetection.isIE ||
            !browserDetection.supportsNativeIntlApi) {
          if (!browserDetection.isOldChrome) {
            dateFixtures['HH'] = '09';
            isoStringWithoutTimeFixtures['HH'] = '00';
          }
          dateFixtures['E'] = 'M';
          dateFixtures['L'] = 'J';
          dateFixtures['m'] = '3';
          dateFixtures['s'] = '1';
          dateFixtures['mm'] = '03';
          dateFixtures['ss'] = '01';
          isoStringWithoutTimeFixtures['m'] = '0';
          isoStringWithoutTimeFixtures['s'] = '0';
          isoStringWithoutTimeFixtures['mm'] = '00';
          isoStringWithoutTimeFixtures['ss'] = '00';
        }

        Object.keys(dateFixtures).forEach((pattern: string) => {
          expectDateFormatAs(date, pattern, dateFixtures[pattern]);
        });

        Object.keys(isoStringWithoutTimeFixtures).forEach((pattern: string) => {
          expectDateFormatAs(isoStringWithoutTime, pattern, isoStringWithoutTimeFixtures[pattern]);
        });

        expect(pipe.transform(date, 'Z')).toBeDefined();
      });
Example #12
0
  describe('DatePipe', () => {
    let date: Date;
    const isoStringWithoutTime = '2015-01-01';
    let pipe: DatePipe;

    // Check the transformation of a date into a pattern
    function expectDateFormatAs(date: Date | string, pattern: any, output: string): void {
      expect(pipe.transform(date, pattern)).toEqual(output);
    }

    // TODO: reactivate the disabled expectations once emulators are fixed in SauceLabs
    // In some old versions of Chrome in Android emulators, time formatting returns dates in the
    // timezone of the VM host,
    // instead of the device timezone. Same symptoms as
    // https://bugs.chromium.org/p/chromium/issues/detail?id=406382
    // This happens locally and in SauceLabs, so some checks are disabled to avoid failures.
    // Tracking issue: https://github.com/angular/angular/issues/11187

    beforeEach(() => {
      date = new Date(2015, 5, 15, 9, 3, 1);
      pipe = new DatePipe('en-US');
    });

    it('should be marked as pure', () => {
      expect(new PipeResolver(new JitReflector()).resolve(DatePipe) !.pure).toEqual(true);
    });

    describe('supports', () => {
      it('should support date', () => { expect(() => pipe.transform(date)).not.toThrow(); });

      it('should support int', () => { expect(() => pipe.transform(123456789)).not.toThrow(); });

      it('should support numeric strings',
         () => { expect(() => pipe.transform('123456789')).not.toThrow(); });

      it('should support decimal strings',
         () => { expect(() => pipe.transform('123456789.11')).not.toThrow(); });

      it('should support ISO string',
         () => expect(() => pipe.transform('2015-06-15T21:43:11Z')).not.toThrow());

      it('should return null for empty string', () => expect(pipe.transform('')).toEqual(null));

      it('should return null for NaN', () => expect(pipe.transform(Number.NaN)).toEqual(null));

      it('should support ISO string without time',
         () => { expect(() => pipe.transform(isoStringWithoutTime)).not.toThrow(); });

      it('should not support other objects',
         () => expect(() => pipe.transform({})).toThrowError(/InvalidPipeArgument/));
    });

    describe('transform', () => {
      it('should format each component correctly', () => {
        const dateFixtures: any = {
          'y': '2015',
          'yy': '15',
          'M': '6',
          'MM': '06',
          'MMM': 'Jun',
          'MMMM': 'June',
          'd': '15',
          'dd': '15',
          'EEE': 'Mon',
          'EEEE': 'Monday'
        };

        const isoStringWithoutTimeFixtures: any = {
          'y': '2015',
          'yy': '15',
          'M': '1',
          'MM': '01',
          'MMM': 'Jan',
          'MMMM': 'January',
          'd': '1',
          'dd': '01',
          'EEE': 'Thu',
          'EEEE': 'Thursday'
        };

        if (!browserDetection.isOldChrome) {
          dateFixtures['h'] = '9';
          dateFixtures['hh'] = '09';
          dateFixtures['j'] = '9 AM';
          isoStringWithoutTimeFixtures['h'] = '12';
          isoStringWithoutTimeFixtures['hh'] = '12';
          isoStringWithoutTimeFixtures['j'] = '12 AM';
        }

        // IE and Edge can't format a date to minutes and seconds without hours
        if (!browserDetection.isEdge && !browserDetection.isIE ||
            !browserDetection.supportsNativeIntlApi) {
          if (!browserDetection.isOldChrome) {
            dateFixtures['HH'] = '09';
            isoStringWithoutTimeFixtures['HH'] = '00';
          }
          dateFixtures['E'] = 'M';
          dateFixtures['L'] = 'J';
          dateFixtures['m'] = '3';
          dateFixtures['s'] = '1';
          dateFixtures['mm'] = '03';
          dateFixtures['ss'] = '01';
          isoStringWithoutTimeFixtures['m'] = '0';
          isoStringWithoutTimeFixtures['s'] = '0';
          isoStringWithoutTimeFixtures['mm'] = '00';
          isoStringWithoutTimeFixtures['ss'] = '00';
        }

        Object.keys(dateFixtures).forEach((pattern: string) => {
          expectDateFormatAs(date, pattern, dateFixtures[pattern]);
        });

        Object.keys(isoStringWithoutTimeFixtures).forEach((pattern: string) => {
          expectDateFormatAs(isoStringWithoutTime, pattern, isoStringWithoutTimeFixtures[pattern]);
        });

        expect(pipe.transform(date, 'Z')).toBeDefined();
      });

      it('should format common multi component patterns', () => {
        const dateFixtures: any = {
          'EEE, M/d/y': 'Mon, 6/15/2015',
          'EEE, M/d': 'Mon, 6/15',
          'MMM d': 'Jun 15',
          'dd/MM/yyyy': '15/06/2015',
          'MM/dd/yyyy': '06/15/2015',
          'yMEEEd': '20156Mon15',
          'MEEEd': '6Mon15',
          'MMMd': 'Jun15',
          'yMMMMEEEEd': 'Monday, June 15, 2015'
        };

        // IE and Edge can't format a date to minutes and seconds without hours
        if (!browserDetection.isEdge && !browserDetection.isIE ||
            !browserDetection.supportsNativeIntlApi) {
          dateFixtures['ms'] = '31';
        }

        if (!browserDetection.isOldChrome) {
          dateFixtures['jm'] = '9:03 AM';
        }

        Object.keys(dateFixtures).forEach((pattern: string) => {
          expectDateFormatAs(date, pattern, dateFixtures[pattern]);
        });

      });

      it('should format with pattern aliases', () => {
        const dateFixtures: any = {
          'MM/dd/yyyy': '06/15/2015',
          'fullDate': 'Monday, June 15, 2015',
          'longDate': 'June 15, 2015',
          'mediumDate': 'Jun 15, 2015',
          'shortDate': '6/15/2015'
        };

        if (!browserDetection.isOldChrome) {
          // IE and Edge do not add a coma after the year in these 2 cases
          if ((browserDetection.isEdge || browserDetection.isIE) &&
              browserDetection.supportsNativeIntlApi) {
            dateFixtures['medium'] = 'Jun 15, 2015 9:03:01 AM';
            dateFixtures['short'] = '6/15/2015 9:03 AM';
          } else {
            dateFixtures['medium'] = 'Jun 15, 2015, 9:03:01 AM';
            dateFixtures['short'] = '6/15/2015, 9:03 AM';
          }
        }

        if (!browserDetection.isOldChrome) {
          dateFixtures['mediumTime'] = '9:03:01 AM';
          dateFixtures['shortTime'] = '9:03 AM';
        }

        Object.keys(dateFixtures).forEach((pattern: string) => {
          expectDateFormatAs(date, pattern, dateFixtures[pattern]);
        });

      });

      it('should format invalid in IE ISO date',
         () => expect(pipe.transform('2017-01-11T09:25:14.014-0500')).toEqual('Jan 11, 2017'));

      it('should format invalid in Safari ISO date',
         () => expect(pipe.transform('2017-01-20T19:00:00+0000')).toEqual('Jan 20, 2017'));

      it('should remove bidi control characters',
         () => expect(pipe.transform(date, 'MM/dd/yyyy') !.length).toEqual(10));
    });
  });
Example #13
0
 transform(value: string) {
    var datePipe = new DatePipe("EST");
     value = datePipe.transform(value, 'MM/dd/yyyy');
     return value;
 }
 transform(value: any): string {
     let format = "yyyy-MM-dd";
     return this.datePipe.transform(new Date(value), format);
 }
Example #15
0
 it('should show the correct time when the timezone is fixed', () => {
   expect(pipe.transform('2017-06-13T10:14:39+0000', 'shortTime', '+0000'))
       .toEqual('10:14 AM');
   expect(pipe.transform('2017-06-13T10:14:39+0000', 'h:mm a', '+0000')).toEqual('10:14 AM');
 });
Example #16
0
 public getTitle(sync:any) :string {
   let datePipe = new DatePipe("fr");
   let res = sync.id + ' - ' + sync.title + ' (' + datePipe.transform(sync.lastStateDate, "dd/MM/yyyy HH:mm:ss") + ')';
   return res;
 }
Example #17
0
 () => expect(pipe.transform(date, 'MM/dd/yyyy') !.length).toEqual(10));
Example #18
0
  describe('DatePipe', () => {
    let date: Date;
    const isoStringWithoutTime = '2015-01-01';
    let pipe: DatePipe;

    // Check the transformation of a date into a pattern
    function expectDateFormatAs(date: Date | string, pattern: any, output: string): void {
      expect(pipe.transform(date, pattern)).toEqual(output);
    }

    beforeAll(() => {
      registerLocaleData(localeEn, localeEnExtra);
      registerLocaleData(localeDe);
      registerLocaleData(localeHu);
      registerLocaleData(localeSr);
      registerLocaleData(localeTh);
      registerLocaleData(localeAr);
    });

    beforeEach(() => {
      date = new Date(2015, 5, 15, 9, 3, 1, 550);
      pipe = new DatePipe('en-US');
    });

    it('should be marked as pure', () => {
      expect(new PipeResolver(new JitReflector()).resolve(DatePipe) !.pure).toEqual(true);
    });

    describe('supports', () => {
      it('should support date', () => { expect(() => pipe.transform(date)).not.toThrow(); });

      it('should support int', () => { expect(() => pipe.transform(123456789)).not.toThrow(); });

      it('should support numeric strings',
         () => { expect(() => pipe.transform('123456789')).not.toThrow(); });

      it('should support decimal strings',
         () => { expect(() => pipe.transform('123456789.11')).not.toThrow(); });

      it('should support ISO string',
         () => expect(() => pipe.transform('2015-06-15T21:43:11Z')).not.toThrow());

      it('should return null for empty string', () => expect(pipe.transform('')).toEqual(null));

      it('should return null for NaN', () => expect(pipe.transform(Number.NaN)).toEqual(null));

      it('should support ISO string without time',
         () => { expect(() => pipe.transform(isoStringWithoutTime)).not.toThrow(); });

      it('should not support other objects',
         () => expect(() => pipe.transform({})).toThrowError(/InvalidPipeArgument/));
    });

    describe('transform', () => {
      it('should format each component correctly', () => {
        const dateFixtures: any = {
          G: 'AD',
          GG: 'AD',
          GGG: 'AD',
          GGGG: 'Anno Domini',
          GGGGG: 'A',
          y: '2015',
          yy: '15',
          yyy: '2015',
          yyyy: '2015',
          M: '6',
          MM: '06',
          MMM: 'Jun',
          MMMM: 'June',
          MMMMM: 'J',
          L: '6',
          LL: '06',
          LLL: 'Jun',
          LLLL: 'June',
          LLLLL: 'J',
          w: '25',
          ww: '25',
          W: '3',
          d: '15',
          dd: '15',
          E: 'Mon',
          EE: 'Mon',
          EEE: 'Mon',
          EEEE: 'Monday',
          EEEEEE: 'Mo',
          h: '9',
          hh: '09',
          H: '9',
          HH: '09',
          m: '3',
          mm: '03',
          s: '1',
          ss: '01',
          S: '6',
          SS: '55',
          SSS: '550',
          a: 'AM',
          aa: 'AM',
          aaa: 'AM',
          aaaa: 'AM',
          aaaaa: 'a',
          b: 'morning',
          bb: 'morning',
          bbb: 'morning',
          bbbb: 'morning',
          bbbbb: 'morning',
          B: 'in the morning',
          BB: 'in the morning',
          BBB: 'in the morning',
          BBBB: 'in the morning',
          BBBBB: 'in the morning',
        };

        const isoStringWithoutTimeFixtures: any = {
          G: 'AD',
          GG: 'AD',
          GGG: 'AD',
          GGGG: 'Anno Domini',
          GGGGG: 'A',
          y: '2015',
          yy: '15',
          yyy: '2015',
          yyyy: '2015',
          M: '1',
          MM: '01',
          MMM: 'Jan',
          MMMM: 'January',
          MMMMM: 'J',
          L: '1',
          LL: '01',
          LLL: 'Jan',
          LLLL: 'January',
          LLLLL: 'J',
          w: '1',
          ww: '01',
          W: '1',
          d: '1',
          dd: '01',
          E: 'Thu',
          EE: 'Thu',
          EEE: 'Thu',
          EEEE: 'Thursday',
          EEEEE: 'T',
          EEEEEE: 'Th',
          h: '12',
          hh: '12',
          H: '0',
          HH: '00',
          m: '0',
          mm: '00',
          s: '0',
          ss: '00',
          S: '0',
          SS: '00',
          SSS: '000',
          a: 'AM',
          aa: 'AM',
          aaa: 'AM',
          aaaa: 'AM',
          aaaaa: 'a',
          b: 'midnight',
          bb: 'midnight',
          bbb: 'midnight',
          bbbb: 'midnight',
          bbbbb: 'midnight',
          B: 'midnight',
          BB: 'midnight',
          BBB: 'midnight',
          BBBB: 'midnight',
          BBBBB: 'mi',
        };

        Object.keys(dateFixtures).forEach((pattern: string) => {
          expectDateFormatAs(date, pattern, dateFixtures[pattern]);
        });

        Object.keys(isoStringWithoutTimeFixtures).forEach((pattern: string) => {
          expectDateFormatAs(isoStringWithoutTime, pattern, isoStringWithoutTimeFixtures[pattern]);
        });
      });

      it('should format with timezones', () => {
        const dateFixtures: any = {
          z: /GMT(\+|-)\d/,
          zz: /GMT(\+|-)\d/,
          zzz: /GMT(\+|-)\d/,
          zzzz: /GMT(\+|-)\d{2}\:30/,
          Z: /(\+|-)\d{2}30/,
          ZZ: /(\+|-)\d{2}30/,
          ZZZ: /(\+|-)\d{2}30/,
          ZZZZ: /GMT(\+|-)\d{2}\:30/,
          ZZZZZ: /(\+|-)\d{2}\:30/,
          O: /GMT(\+|-)\d/,
          OOOO: /GMT(\+|-)\d{2}\:30/,
        };

        Object.keys(dateFixtures).forEach((pattern: string) => {
          expect(pipe.transform(date, pattern, '+0430')).toMatch(dateFixtures[pattern]);
        });
      });

      it('should format common multi component patterns', () => {
        const dateFixtures: any = {
          'EEE, M/d/y': 'Mon, 6/15/2015',
          'EEE, M/d': 'Mon, 6/15',
          'MMM d': 'Jun 15',
          'dd/MM/yyyy': '15/06/2015',
          'MM/dd/yyyy': '06/15/2015',
          'yMEEEd': '20156Mon15',
          'MEEEd': '6Mon15',
          'MMMd': 'Jun15',
          'EEEE, MMMM d, y': 'Monday, June 15, 2015',
          'H:mm a': '9:03 AM',
          'ms': '31',
          'MM/dd/yy hh:mm': '06/15/15 09:03',
          'MM/dd/y': '06/15/2015'
        };

        Object.keys(dateFixtures).forEach((pattern: string) => {
          expectDateFormatAs(date, pattern, dateFixtures[pattern]);
        });

      });

      it('should format with pattern aliases', () => {
        const dateFixtures: any = {
          'MM/dd/yyyy': '06/15/2015',
          shortDate: '6/15/15',
          mediumDate: 'Jun 15, 2015',
          longDate: 'June 15, 2015',
          fullDate: 'Monday, June 15, 2015',
          short: '6/15/15, 9:03 AM',
          medium: 'Jun 15, 2015, 9:03:01 AM',
          long: /June 15, 2015 at 9:03:01 AM GMT(\+|-)\d/,
          full: /Monday, June 15, 2015 at 9:03:01 AM GMT(\+|-)\d{2}:\d{2}/,
          shortTime: '9:03 AM',
          mediumTime: '9:03:01 AM',
          longTime: /9:03:01 AM GMT(\+|-)\d/,
          fullTime: /9:03:01 AM GMT(\+|-)\d{2}:\d{2}/,
        };

        Object.keys(dateFixtures).forEach((pattern: string) => {
          expect(pipe.transform(date, pattern)).toMatch(dateFixtures[pattern]);
        });
      });

      it('should format invalid in IE ISO date',
         () => expect(pipe.transform('2017-01-11T12:00:00.014-0500')).toEqual('Jan 11, 2017'));

      it('should format invalid in Safari ISO date',
         () => expect(pipe.transform('2017-01-20T12:00:00+0000')).toEqual('Jan 20, 2017'));

      // test for the following bugs:
      // https://github.com/angular/angular/issues/9524
      // https://github.com/angular/angular/issues/9524
      it('should format correctly with iso strings that contain time',
         () => expect(pipe.transform('2017-05-07T22:14:39', 'dd-MM-yyyy HH:mm'))
                   .toMatch(/07-05-2017 \d{2}:\d{2}/));

      // test for issue https://github.com/angular/angular/issues/21491
      it('should not assume UTC for iso strings in Safari if the timezone is not defined', () => {
        // this test only works if the timezone is not in UTC
        // which is the case for BrowserStack when we test Safari
        if (new Date().getTimezoneOffset() !== 0) {
          expect(pipe.transform('2018-01-11T13:00:00', 'HH'))
              .not.toEqual(pipe.transform('2018-01-11T13:00:00Z', 'HH'));
        }
      });

      // test for the following bugs:
      // https://github.com/angular/angular/issues/16624
      // https://github.com/angular/angular/issues/17478
      it('should show the correct time when the timezone is fixed', () => {
        expect(pipe.transform('2017-06-13T10:14:39+0000', 'shortTime', '+0000'))
            .toEqual('10:14 AM');
        expect(pipe.transform('2017-06-13T10:14:39+0000', 'h:mm a', '+0000')).toEqual('10:14 AM');
      });

      it('should remove bidi control characters',
         () => expect(pipe.transform(date, 'MM/dd/yyyy') !.length).toEqual(10));

      it(`should format the date correctly in various locales`, () => {
        expect(new DatePipe('de').transform(date, 'short')).toEqual('15.06.15, 09:03');
        expect(new DatePipe('ar').transform(date, 'short')).toEqual('15‏/6‏/2015 9:03 ص');
        expect(new DatePipe('th').transform(date, 'dd-MM-yy')).toEqual('15-06-15');
        expect(new DatePipe('hu').transform(date, 'a')).toEqual('de.');
        expect(new DatePipe('sr').transform(date, 'a')).toEqual('пре подне');

        // TODO(ocombe): activate this test when we support local numbers
        // expect(new DatePipe('mr', [localeMr]).transform(date, 'hh')).toEqual('०९');
      });

      it('should throw if we use getExtraDayPeriods without loading extra locale data', () => {
        expect(() => new DatePipe('de').transform(date, 'b'))
            .toThrowError(/Missing extra locale data for the locale "de"/);
      });
    });
  });
Example #19
0
 it('should return null for NaN', () => expect(pipe.transform(Number.NaN)).toEqual(null));
Example #20
0
 // Check the transformation of a date into a pattern
 function expectDateFormatAs(date: Date | string, pattern: any, output: string): void {
   expect(pipe.transform(date, pattern)).toEqual(output);
 }
Example #21
0
 () => expect(() => pipe.transform({})).toThrowError(/InvalidPipeArgument/));
Example #22
0
 Object.keys(dateFixtures).forEach((pattern: string) => {
   expect(pipe.transform(date, pattern)).toMatch(dateFixtures[pattern]);
 });
Example #23
0
 () => { expect(pipe.transform(date, 'MM/dd/yyyy').length).toEqual(10); });
Example #24
0
 () => expect(pipe.transform('2017-01-11T12:00:00.014-0500')).toEqual('Jan 11, 2017'));
Example #25
0
 it('should support date', () => { expect(() => pipe.transform(date)).not.toThrow(); });
Example #26
0
 () => expect(pipe.transform('2017-01-20T12:00:00+0000')).toEqual('Jan 20, 2017'));
Example #27
0
 () => { expect(() => pipe.transform('123456789.11')).not.toThrow(); });
Example #28
0
 () => expect(pipe.transform('2017-05-07T22:14:39', 'dd-MM-yyyy HH:mm'))
           .toMatch(/07-05-2017 \d{2}:\d{2}/));
Example #29
0
 expect(() => pipe.transform('')).toThrow();
describe('EpisodesComponent', () => {
	let component: EpisodesComponent;
	let fixture: ComponentFixture<EpisodesComponent>;
	let el: DebugElement;
  let store: Store<PodcastState>;
	let datePipe: DatePipe;

	beforeEach(
		async(() => {
			TestBed.configureTestingModule({
				declarations: [EpisodesComponent],
				imports: [
					MatListModule,
          MatPaginatorModule,
          RouterTestingModule.withRoutes([]),

					StoreModule.forRoot({}),
					StoreModule.forFeature('podcast', fromPodcast.reducer),

					RouterTestingModule
				],
			}).compileComponents();

			datePipe = new DatePipe('en-US');
		})
	);

  beforeEach(async () => {
    store = TestBed.get(Store);
    spyOn(store, 'dispatch').and.callThrough();
  });

	beforeEach(async () => {
	  store.dispatch(new FindItemsByPodcastsAndPageSuccessAction(items));
		fixture = TestBed.createComponent(EpisodesComponent);
		component = fixture.componentInstance;
		fixture.detectChanges();
		el = fixture.debugElement;
		await fixture.whenStable();
	});

	it('should create', () => {
	  /* Given */
    /* When */
    /* Then */
		expect(component).toBeTruthy();
	});

	it('should have coherent number of items', () => {
		/* Given */
		/* When  */
		const itemsElement = el.queryAll(By.css('[mat-list-item]'));
		/* Then  */
		expect(itemsElement.length).toEqual(10);
	});

	it('should have each line with cover', () => {
		/* Given */
		const coversExpected = items.content.map(v => v.cover.url);
		/* When  */
		const coversUrl = el.queryAll(By.css('img')).map(v => v.properties.src);
		/* Then  */
		expect(coversExpected).toEqual(coversUrl);
	});

	it('should have each line with title', () => {
		/* Given */
		const titleExpected = items.content.map(v => v.title);
		/* When  */
		const titles = el.queryAll(By.css('h3[matLine]')).map(asText);
		/* Then  */
		expect(titleExpected).toEqual(titles);
	});

	it('should have each line with date', () => {
		/* Given */
		const dateExpected = items.content.map(v => v.pubDate).map(v => datePipe.transform(v, 'dd/MM/yyyy à HH:mm'));
		/* When  */
		const dates = el.queryAll(By.css('p[matLine]')).map(asText);
		/* Then  */
		expect(dateExpected).toEqual(dates);
	});

	function asText(v: DebugElement) {
		return v.nativeElement.textContent.trim();
	}
});