Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Time:
- class Segment
- constructor: (@seconds) ->
- getSeconds: -> if (t = ((@seconds)>>0)%(60))<10 then '0' + t else t
- getMinutes: -> if (t = ((@seconds/60)>>0)%(60))<10 then '0' + t else t
- getHours: -> if (t = ((@seconds/60/60)>>0)%(60))<10 then '0' + t else t
- getDays: -> if (t = ((@seconds/60/60/24)>>0)%(60))<10 then '0' + t else t
- getMonths: (daysPerMonth = 30) -> if (t = ((@seconds/60/60/24/daysPerMonth)>>0)%(60))<10 then '0' + t else t
- namespace Time:
- class Timestamp
- @SYNC: 0
- @SECOND: 1
- @MINUTE: 60
- @HOUR: 3600
- @DAY: 86400
- @MONTH: 2592000 # (bad idea) 30 days per month
- @YEAR: 946080000 # (double bad idea) 30 days per month
- constructor: (@timestamp) ->
- if currentPlayer? && currentPlayer.synchonism?
- @constructor.SYNC = (((new Date()).getTime()/1000)|0) - currentPlayer.synchonism()
- unless @timestamp.toString()
- @timestamp = 0
- return @
- if @timestamp.toString().length > 10
- @timestamp = (@timestamp / 1000)
- @timestamp = @timestamp >> 0
- toString: -> @timestamp
- mod: (date) ->
- @timestamp%date
- date: (string) ->
- zeroFirst = (n) ->
- return if n.toString().length is 1 then '0' + n else n.toString()
- if string
- date = new Date @timestamp * 1000
- return string
- .replace('d', zeroFirst date.getDay())
- .replace('m', zeroFirst date.getMonth())
- .replace('y', date.getFullYear().toString().substr(2, 2))
- .replace('Y', date.getFullYear())
- .replace('h', if h = date.getHours() > 12 then zeroFirst(h - 12) else zeroFirst h)
- .replace('H', zeroFirst date.getHours())
- .replace('i', zeroFirst date.getMinutes())
- .replace('s', zeroFirst date.getSeconds())
- else
- return new Date @timestamp * 1000
- getNow: ->
- (((new Date()).getTime()/1000)|0) - @constructor.SYNC
- # Секунды
- addSecond: (num = 1) -> @timestamp += num
- subSecond: (num = 1) -> @timestamp -= num
- # Минуты
- addMinute: (num = 1) -> @timestamp += (num * @constructor.MINUTE)
- subMinute: (num = 1) -> @timestamp -= (num * @constructor.MINUTE)
- # Часы
- addHour: (num = 1) -> @timestamp += (num * @constructor.HOUR)
- subHour: (num = 1) -> @timestamp -= (num * @constructor.HOUR)
- # Дни
- addDay: (num = 1) -> @timestamp += (num * @constructor.DAY)
- subDay: (num = 1) -> @timestamp -= (num * @constructor.DAY)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement