github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/ekatime/internal.go (about) 1 // Copyright © 2020. All rights reserved. 2 // Author: Ilya Stroy. 3 // Contacts: iyuryevich@pm.me, https://github.com/qioalice 4 // License: https://opensource.org/licenses/MIT 5 6 package ekatime 7 8 import ( 9 "time" 10 ) 11 12 //noinspection GoSnakeCaseUsage 13 const ( 14 SECONDS_IN_MINUTE Timestamp = 60 15 SECONDS_IN_HOUR Timestamp = 3600 16 SECONDS_IN_12H Timestamp = 43200 17 SECONDS_IN_DAY Timestamp = 86400 18 SECONDS_IN_WEEK Timestamp = 604800 19 20 SECONDS_IN_365_YEAR Timestamp = 31536000 21 SECONDS_IN_366_YEAR Timestamp = 31622400 22 ) 23 24 var ( 25 // Table of: 26 // The number of days in month (not leap year). 27 // Consumes 12 bytes in RAM totally. 28 _Table0 = [12]Day{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} 29 30 // Table of: 31 // The number of seconds in month (not leap year). 32 // Consumes 96 bytes in RAM totally. 33 _Table1 = [12]Timestamp{ 34 2678400, 2419200, 2678400, 2592000, 2678400, 2592000, 35 2678400, 2678400, 2592000, 2678400, 2592000, 2678400, 36 } 37 38 // Table of: 39 // The 1st day of each month in the year pov. 40 // Consumes 24 bytes in RAM totally. 41 // It assumes that February has 29 days. 42 _Table2 = [12]Days{1, 32, 61, 92, 122, 153, 183, 214, 245, 275, 306, 336} 43 44 // Table of: 45 // The beginning of month in unix timestamp for [1970..now+10] years. 46 // Consumes 96 byte in RAM per year. 47 // "The beginning of month" is 1st day with 00:00:01 AM clock. 48 // 49 // Assuming, it's 2020 year now, the upper bound will be is 2030 year the 50 // table is being generated for. 51 // So, table will contain 2030-1970 == 60 years and will consume 52 // 53 // 5856 bytes in RAM totally (about 5.7 KB). 54 _Table5 [][12]Timestamp 55 _Table5UpperBound Year // real year, not an index in '_Table5' 56 ) 57 58 func initTable5() { 59 _Table5UpperBound = Year(time.Now().Year()) + 10 60 _Table5 = make([][12]Timestamp, _Table5UpperBound-1970+1) 61 62 d := time.Unix(1, 0) 63 for i, n := 0, len(_Table5); i < n; i++ { 64 for j := 0; j < 12; j++ { 65 _Table5[i][j] = Timestamp(d.Unix()) 66 d = d.AddDate(0, 1, 0) 67 } 68 } 69 }