本文整理汇总了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');
}
}
示例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;
}
示例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;
}
示例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');
});
示例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 + ')';
}
示例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,
};
}
示例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'
}]);
}
示例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);
});
});
})
示例9:
]).spread((time, general) => {
return moment.tz(time.system_time.$date, general.timezone).format('Z');
});
示例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;
}
示例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
//.........这里部分代码省略.........
示例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;
}