mirror of
https://github.com/samsonjs/strftime.git
synced 2026-04-27 14:57:37 +00:00
code style
This commit is contained in:
parent
f1581a3c9d
commit
6ab81c89cb
1 changed files with 13 additions and 11 deletions
24
strftime.js
24
strftime.js
|
|
@ -87,35 +87,36 @@
|
||||||
_customTimezoneOffset = customTimezoneOffset || 0,
|
_customTimezoneOffset = customTimezoneOffset || 0,
|
||||||
_useUtcBasedDate = useUtcTimezone || false,
|
_useUtcBasedDate = useUtcTimezone || false,
|
||||||
|
|
||||||
// we store unix timestamp value here to not create new Date() each iteration (each millisecond)
|
// we store unix timestamp value here to not create new Date() each iteration (each millisecond)
|
||||||
// Date.now() is 2 times faster than new Date()
|
// Date.now() is 2 times faster than new Date()
|
||||||
// while millisecond precise is enough here
|
// while millisecond precise is enough here
|
||||||
// this could be very helpful when strftime triggered a lot of times one by one
|
// this could be very helpful when strftime triggered a lot of times one by one
|
||||||
_cachedDateTimestamp = 0,
|
_cachedDateTimestamp = 0,
|
||||||
_cachedDate;
|
_cachedDate;
|
||||||
|
|
||||||
function _strftime(format, date) {
|
function _strftime(format, date) {
|
||||||
var timestamp;
|
var timestamp;
|
||||||
|
|
||||||
if(!date) {
|
if (!date) {
|
||||||
var currentTimestamp = Date.now();
|
var currentTimestamp = Date.now();
|
||||||
if(currentTimestamp > _cachedDateTimestamp) {
|
if (currentTimestamp > _cachedDateTimestamp) {
|
||||||
_cachedDateTimestamp = currentTimestamp;
|
_cachedDateTimestamp = currentTimestamp;
|
||||||
_cachedDate = new Date(_cachedDateTimestamp);
|
_cachedDate = new Date(_cachedDateTimestamp);
|
||||||
|
|
||||||
timestamp = _cachedDateTimestamp;
|
timestamp = _cachedDateTimestamp;
|
||||||
|
|
||||||
if(_useUtcBasedDate) {
|
if (_useUtcBasedDate) {
|
||||||
// how to avoid duplication of date instantiation for utc here?
|
// how to avoid duplication of date instantiation for utc here?
|
||||||
// we tied to getTimezoneOffset of the current date
|
// we tied to getTimezoneOffset of the current date
|
||||||
_cachedDate = new Date(_cachedDateTimestamp + getTimestampToUtcOffsetFor(_cachedDate) + _customTimezoneOffset);
|
_cachedDate = new Date(_cachedDateTimestamp + getTimestampToUtcOffsetFor(_cachedDate) + _customTimezoneOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
date = _cachedDate;
|
date = _cachedDate;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
timestamp = date.getTime();
|
timestamp = date.getTime();
|
||||||
|
|
||||||
if(_useUtcBasedDate) {
|
if (_useUtcBasedDate) {
|
||||||
date = new Date(date.getTime() + getTimestampToUtcOffsetFor(date) + _customTimezoneOffset);
|
date = new Date(date.getTime() + getTimestampToUtcOffsetFor(date) + _customTimezoneOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +134,7 @@
|
||||||
|
|
||||||
var currentCharCode = format.charCodeAt(i);
|
var currentCharCode = format.charCodeAt(i);
|
||||||
|
|
||||||
if(isInScope === true) {
|
if (isInScope === true) {
|
||||||
// '-'
|
// '-'
|
||||||
if (currentCharCode === 45) {
|
if (currentCharCode === 45) {
|
||||||
padding = '';
|
padding = '';
|
||||||
|
|
@ -442,7 +443,8 @@
|
||||||
|
|
||||||
customTimezoneOffset = sign * ((60 * hours) + minutes) * 60 * 1000;
|
customTimezoneOffset = sign * ((60 * hours) + minutes) * 60 * 1000;
|
||||||
// in minutes: 420
|
// in minutes: 420
|
||||||
} else if (timezoneType === 'number'){
|
}
|
||||||
|
else if (timezoneType === 'number') {
|
||||||
customTimezoneOffset = timezone * 60 * 1000;
|
customTimezoneOffset = timezone * 60 * 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue