當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript moment-timezone.tz函數代碼示例

本文整理匯總了TypeScript中moment-timezone.tz函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript tz函數的具體用法?TypeScript tz怎麽用?TypeScript tz使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了tz函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: transform

  transform(value: any, timezoneFrom?: string, timezoneTo?: string): string {
    if (typeof value === 'string') {
      value = parseInt(value, 10);

      if (isNaN(value)) {
        return '';
      }
    }

    if (typeof value !== 'number' && !(value instanceof Date) && !moment.isMoment(value)) {
      return '';
    }

    if (!timezoneFrom) {
      return typeof value === 'number'
        ? this.hourToString(value)
        : moment.utc(value).format('HH:mm');
    } else {
      timezoneTo = timezoneTo ? timezoneTo : moment.tz.guess();

      return moment
        .tz(
          typeof value === 'number'
            ? this.hourToString(value)
            : moment.utc(value).format('HH:mm'),
          'HH:mm',
          timezoneFrom
        )
        .tz(timezoneTo)
        .format('HH:mm');
    }
  }
開發者ID:Sirimangalo,項目名稱:meditation-plus-angular,代碼行數:32,代碼來源:hour.pipe.ts

示例2: isNearTo5PM

    public isNearTo5PM(fromPage:string):boolean{
        var nearTo5PMFlag:boolean = false;
        let dt = moment.now();
        let now = moment.tz(dt, 'America/Chicago');

        var hour:number = now.hour();
        var minute:number = now.minute();
        var dayOfWeek:number = now.day();
        LoggerUtil.info("Hour:::"+hour +" :::minute:::"+minute + " :::dayOfWeek:::"+dayOfWeek)

        if(CommonUtil.isNotBlank(fromPage) && CommonUtil.equalsIgnoreCase(fromPage,"StartService")){
            if((dayOfWeek != 0 )&& (((hour == 16)&& (minute >=30 && minute <=45)))) {
                nearTo5PMFlag = true;
            } else {
                nearTo5PMFlag = false;
            }
            LoggerUtil.info("nearTo5PMFlag in dateUtil::"+nearTo5PMFlag)
        }else if(CommonUtil.isNotBlank(fromPage) && CommonUtil.equalsIgnoreCase(fromPage,"Verify")){
            if((dayOfWeek != 0 )&& (((hour == 16)&& (minute >=45)) || (hour > 16)))  {
                nearTo5PMFlag = true;
            } else {
                nearTo5PMFlag = false;
            }
        }
        return nearTo5PMFlag;
    }
開發者ID:bbachi,項目名稱:Angular5Sample,代碼行數:26,代碼來源:date.util.ts

示例3: getTimeStamp

    public getTimeStamp(): string {

        let dt = moment.now();
        let newDate= moment.tz(dt, 'America/Chicago').format("MM/DD/YYYY HH:mm:ss")
        //console.log("date TS for logs:::" +newDate)
        return newDate;

    }
開發者ID:bbachi,項目名稱:Angular5Sample,代碼行數:8,代碼來源:date.util.ts

示例4: it

 it('should format date/moment objects correctly', () => {
   expect(pipe.transform(new Date(Date.UTC(2017,  9, 26, 10, 10, 0)))).toBe('10:10');
   expect(pipe.transform(new Date('2014-06-01T00:06:00Z'))).toBe('00:06');
   expect(pipe.transform(new Date('2014-06-01T23:59:00Z'))).toBe('23:59');
   expect(pipe.transform(moment('2014-06-01T23:59:00Z'))).toBe('23:59');
   expect(pipe.transform(moment.utc('2014-06-01T23:59:00Z'))).toBe('23:59');
   expect(pipe.transform(moment.tz('2014-06-01T23:59:00Z', 'Asia/Tokyo'))).toBe('23:59');
 });
開發者ID:Sirimangalo,項目名稱:meditation-plus-angular,代碼行數:8,代碼來源:hour.pipe.spec.ts

示例5: timezoneOffset

 /** Get offset of timezone */
 timezoneOffset(zone: string): string {
   let offset = moment.tz(zone).utcOffset();
   const neg = offset < 0;
   if (neg) {
     offset = -1 * offset;
   }
   const hours = Math.floor(offset / 60);
   const minutes = (offset / 60 - hours) * 60;
   let sym = neg ? '-' : '+';
   let paddedHours = this.pad(hours.toString());
   let paddedMinutes = this.pad(minutes.toString());
   return '(GMT' + sym + paddedHours + ':' + paddedMinutes + ')';
 }
開發者ID:bluecaret,項目名稱:carettab,代碼行數:14,代碼來源:timezone.service.ts

示例6: createEvent

function createEvent(attrs: {
  id: string | number,
  start: string,
  duration: number,
  timezone?: string,
  allDay?: boolean,
}) {
  let tz = attrs.timezone || 'US/Pacific';
  return {
    id: attrs.id,
    start: moment.tz(attrs.start, 'YYYY-MM-DD HH:mm', tz),
    duration: attrs.duration || 60,
  };
}
開發者ID:lehresman,項目名稱:callay-engine,代碼行數:14,代碼來源:engine.spec.ts

示例7: respond

    public respond() {
      const londonDate = new Date();
      const lvivDate = moment.tz(londonDate, 'Europe/Kiev');

      this._callback([{
          "color": global['hexGenerator'](),
          "fields": [
            {
              "title": 'London (GB)',
              "value": `${this._padNumber(londonDate.getDate())} ${this.months[londonDate.getMonth()]} ${londonDate.getFullYear()}, ${this._padNumber(londonDate.getHours())}:${this._padNumber(londonDate.getMinutes())}`,
              "short": true
            },
            {
              "title": 'Lviv (UKR)',
              "value": `${lvivDate.format('DD')} ${this.months[parseInt(lvivDate.format('M'), 10)]} ${lvivDate.format('YYYY')}, ${lvivDate.format('HH')}:${lvivDate.format('mm')}`,
              "short": true
            }
          ],
          "image_url": 'http://benderthebot.herokuapp.com/icons/time.png'
      }]);
    }
開發者ID:SlimDogs,項目名稱:bender-slack-bot,代碼行數:21,代碼來源:callback.ts

示例8: Promise

  return new Promise(function (resolve, reject) {
    let localDB=PouchDB(localdb);
    let partialsDB=PouchDB(partialsdb+'_'+data.uid+'_year',{auto_compaction: true});



    let dateDay=parseInt(data.date[6]+data.date[7]);
    let dateMonth=parseInt(data.date[4]+data.date[5]);
    let dateforYear=parseInt(data.date[0]+data.date[1]+data.date[2]+data.date[3]);

    let dateBeginningOfDay=moment.tz(dateforYear+' '+dateMonth+' '+dateDay,"YYYY MM DD",timezone).valueOf();
    let dateBeginningOfMonth=moment.tz(dateforYear+' '+dateMonth+' 01',"YYYY MM DD",timezone).valueOf();
    let dateBeginningOfYear=moment.tz(dateforYear+' 01 01',"YYYY MM DD",timezone).valueOf();

    let dateforDay=parseInt(dateforYear+data.date[4]+data.date[5]+dateDay);
    let dateforMonth=parseInt(dateforYear+data.date[4]+data.date[5]);




        partialsDB.get('yearly_'+data.uid).then(function(yearPower){


          if( yearPower.dateBeginningOfYear != dateBeginningOfYear ){



            let yearlynew={
              _id:'yearly_'+data.uid+'_'+yearPower.dateforYear,
              power:yearPower.power,
              updatedAt:yearPower.dateBeginningOfYear
            };

            localDB.put(yearlynew).then(function(doc){

              yearPower.power=data.yearlyEnergy;
              yearPower.dateBeginningOfYear=dateBeginningOfYear;
              yearPower.dateforYear=dateforYear;


              partialsDB.destroy().then(function(){
                let partialsDB=PouchDB(partialsdb+'_'+data.uid+'_year',{auto_compaction: true});

                delete yearPower._rev
              partialsDB.put(yearPower).then(function(){

                resolve(true);
              }).catch(function(err){
                reject(err);
              });
});

            }).catch(function(err){
reject(err);
            });

          } else{
            yearPower.power=data.yearlyEnergy;
            yearPower.dateBeginningOfYear=dateBeginningOfYear;
            yearPower.dateforYear=dateforYear;
            partialsDB.destroy().then(function(){
              let partialsDB=PouchDB(partialsdb+'_'+data.uid+'_year',{auto_compaction: true});

              delete yearPower._rev
            partialsDB.put(yearPower).then(function(){

              resolve(true);
            }).catch(function(err){
              reject(err);
            });
  });
          }



        }).catch(function(){
          let yearly={
            _id:'yearly_'+data.uid,
            dateBeginningOfYear:dateBeginningOfYear,
            power:data.yearlyEnergy,
            dateforYear:dateforYear
          };
          partialsDB.put(yearly).then(function(){

            resolve(true);
          }).catch(function(err){
            reject(err);
          });
        });




})
開發者ID:dottgonzo,項目名稱:express-autoaurora,代碼行數:94,代碼來源:setpowerpartials.ts

示例9:

 ]).spread((time, general) => {
     return moment.tz(time.system_time.$date, general.timezone).format('Z');
 });
開發者ID:mactanxin,項目名稱:gui,代碼行數:3,代碼來源:system-repository.ts

示例10: prodStartTasks

});

router.post("/stale", (req, res, next) => {
    prodStartTasks()
    .then(() => logger.info(`Finished running recover job`))
    .then(() => res.send("OK"))
    .catch((err) => {
        logger.error(err);
        res.sendStatus(500);
    });
});

const now = moment().tz(TIME_ZONE);
const timeFormat = "HH:mm";
for (let job of jobSchedule) {
    const startTime = moment.tz(job.startTime, timeFormat, TIME_ZONE);
    const endTime = moment.tz(job.endTime, timeFormat, TIME_ZONE);
    const correctTime = now.isBetween(startTime, endTime);
    const correctDay = job.weekdays.includes(now.weekday());
    if (!correctDay) {
        logger.info(`not correct day (${now.weekday()}) to run job: ${job.name}`);
        continue;
    }
    if (!correctTime) {
        logger.info(`not correct time (${now.format(timeFormat)}) to run job: ${job.name}`);
        continue;
    }
    if (!job.enabled) {
        logger.info(`Job is disabled: ${job.name}`);
        continue;
    }
開發者ID:CMUBigLab,項目名稱:cmuNodeFbot,代碼行數:31,代碼來源:index.ts

示例11: describe

describe('monthLayoutFor', () => {
  let tz = 'Europe/Berlin';
  let startDate = moment.tz('2018-01-01 00:00', tz);
  let endDate = moment.tz('2018-01-15 00:00', tz);

  it('should properly position a single event', () => {
    let events: TestEvent[] = [new TestEvent({start: '2018-01-01 08:00', duration: 60})];
    let weeks = monthLayoutFor(startDate, endDate, events);

    expect(weeks.length).toBe(3);
    expect(weeks[0].days[1].dateStr).toBe('2018-01-01');
    expect(weeks[0].days[1].entries.length).toBe(1);
    expect(weeks[0].days[1].entries[0].isStart).toBe(true);
    expect(weeks[0].days[1].entries[0].isEnd).toBe(true);
  });

  it('should properly position the levels for multiple events', () => {
    let events: TestEvent[] = [
      new TestEvent({start: '2018-01-02 14:00', duration: 60}), // will not be added to 2018-01-01
      new TestEvent({start: '2018-01-01 10:15', duration: 60}),
      new TestEvent({start: '2018-01-01 08:00', duration: 60}),
    ];
    let weeks = monthLayoutFor(startDate, endDate, events);
    expect(weeks[0].days[1].entries.length).toBe(2);
    expect(weeks[0].days[1].entries[0].originalEvent.start.hours()).toBe(8);
    expect(weeks[0].days[1].entries[0].level).toBe(0);
    expect(weeks[0].days[1].entries[1].originalEvent.start.hours()).toBe(10);
    expect(weeks[0].days[1].entries[1].level).toBe(1);
  });

  it('should properly calculate spanning events in the same week', () => {
    let firstEvent = new TestEvent({start: '2018-01-02 14:00', duration: 60});
    let secondEvent = new TestEvent({start: '2018-01-01 10:15', duration: 60*48});
    let thirdEvent = new TestEvent({start: '2018-01-01 08:00', duration: 60});
    let fourthEvent = new TestEvent({start: '2018-01-03 08:00', duration: 30});
    let fifthEvent = new TestEvent({start: '2018-01-03 09:00', duration: 30});
    let events: TestEvent[] = [firstEvent, secondEvent, thirdEvent, fourthEvent, fifthEvent];
    let weeks = monthLayoutFor(startDate, endDate, events);

    // 2018-01-01
    expect(weeks[0].days[1].entries.length).toBe(2);

    expect(weeks[0].days[1].entries[0].id).toBe(thirdEvent.id);
    expect(weeks[0].days[1].entries[0].isStart).toBe(true);
    expect(weeks[0].days[1].entries[0].isEnd).toBe(true);
    expect(weeks[0].days[1].entries[0].level).toBe(0);
    expect(weeks[0].days[1].entries[0].span).toBe(1);

    expect(weeks[0].days[1].entries[1].id).toBe(secondEvent.id);
    expect(weeks[0].days[1].entries[1].isStart).toBe(true);
    expect(weeks[0].days[1].entries[1].isEnd).toBe(true);
    expect(weeks[0].days[1].entries[1].level).toBe(1);
    expect(weeks[0].days[1].entries[1].span).toBe(3);

    // 2018-01-02
    expect(weeks[0].days[2].entries.length).toBe(1);

    expect(weeks[0].days[2].entries[0].id).toBe(firstEvent.id);
    expect(weeks[0].days[2].entries[0].level).toBe(0);
    expect(weeks[0].days[2].entries[0].span).toBe(1);

    // 2018-01-03
    expect(weeks[0].days[3].entries.length).toBe(2);

    expect(weeks[0].days[3].entries[0].id).toBe(fourthEvent.id);
    expect(weeks[0].days[3].entries[0].level).toBe(0);
    expect(weeks[0].days[3].entries[0].span).toBe(1);

    expect(weeks[0].days[3].entries[1].id).toBe(fifthEvent.id);
    expect(weeks[0].days[3].entries[1].level).toBe(2);
    expect(weeks[0].days[3].entries[1].span).toBe(1);
  });

  it('should properly span multi-day events across two weeks', () => {
    let longEvent = new TestEvent({start: '2018-01-06 10:15', duration: 60*24*4});
    let events: TestEvent[] = [
      new TestEvent({start: '2018-01-06 09:00', duration: 30}),
      longEvent,
      new TestEvent({start: '2018-01-07 09:00', duration: 30}),
    ];
    let weeks = monthLayoutFor(startDate, endDate, events);

    // 2018-01-06 (Saturday)
    expect(weeks[0].days[6].entries.length).toBe(2);
    expect(weeks[0].days[6].entries[0].id).not.toBe(longEvent.id);
    expect(weeks[0].days[6].entries[1].id).toBe(longEvent.id);
    expect(weeks[0].days[6].entries[1].span).toBe(1); // 1 because only 1 day left this week
    expect(weeks[0].days[6].entries[1].isStart).toBe(true);
    expect(weeks[0].days[6].entries[1].isEnd).toBe(false);

    // 2018-01-07 (Sunday)
    expect(weeks[1].days[0].entries.length).toBe(2);
    expect(weeks[1].days[0].entries[0].id).not.toBe(longEvent.id);
    expect(weeks[1].days[0].entries[1].id).toBe(longEvent.id);
    expect(weeks[1].days[0].entries[1].span).toBe(4);
    expect(weeks[1].days[0].entries[1].isStart).toBe(false);
    expect(weeks[1].days[0].entries[1].isEnd).toBe(true);

    // 2018-01-09 (Tuesday)
    // Even though longEvent spans through Tuesday, the entry is added
//.........這裏部分代碼省略.........
開發者ID:lehresman,項目名稱:callay-engine,代碼行數:101,代碼來源:engine.spec.ts

示例12: constructor

 constructor(attrs: any) {
   this.id = uuid();
   this.start = moment.tz(attrs.start, attrs.timezone || 'Europe/Berlin');
   this.duration = attrs.duration;
   this.isAllDay = attrs.isAllDay || false;
 }
開發者ID:lehresman,項目名稱:callay-engine,代碼行數:6,代碼來源:engine.spec.ts


注:本文中的moment-timezone.tz函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。