PageSourceSearch

https://thai-mecc.go.th/share/js/utils/DateUtils.js

js thai-mecc.go.th collected 2026-10-09 03:35:21 UTC 4,580 bytes, 122 lines download raw bytes

1Date.prototype.weekDayLocale = {}
2Date.prototype.weekDayLocale['narrow'] = {
3	'th': new Intl.DateTimeFormat('th-TH', {weekday: 'narrow'}), 
4	'en': new Intl.DateTimeFormat('en-US', {weekday: 'narrow'})
5}
6Date.prototype.weekDayLocale['short'] = {
7	'th': new Intl.DateTimeFormat('th-TH', {weekday: 'short'}), 
8	'en': new Intl.DateTimeFormat('en-US', {weekday: 'short'})
9}
10Date.prototype.weekDayLocale['long'] = {
11	'th': new Intl.DateTimeFormat('th-TH', {weekday: 'long'}), 
12	'en': new Intl.DateTimeFormat('en-US', {weekday: 'long'})
13}
14
15Date.prototype.getAllWeekDay = function(type) {
16	if (type == undefined) type = 'short';
17	let weekdays = [];
18	let sunday = (new Date()).getSunday();
19	weekdays.push(Date.prototype.weekDayLocale[type][LANGUAGE].format(sunday));
20	for (let i in [...Array(6).keys()]) {
21		sunday.setDate(sunday.getDate() + 1);
22		weekdays.push(Date.prototype.weekDayLocale[type][LANGUAGE].format(sunday));
23	}
24	return weekdays;
25}
26
27Date.prototype.getSunday = function() {
28	const first = this.getDate() - this.getDay() + 1;
29	const last = first + 6;
30	const sunday = new Date(this.setDate(last));
31	return sunday;
32}
33
34Date.prototype.getWeekOfMonth = function() {
35	let year = this.getFullYear();
36	let month = this.getMonth();
37	let firstDay = new Date(year, month, 1);
38	let firstIndex = parseInt(firstDay.getDay());
39	let j = parseInt(this.getDate() - 1) + firstIndex;
40	let week = parseInt(Math.floor(j / 7));
41	return week;
42}
43
44Date.prototype.resetTime = function() {
45	this.setHours(0);
46	this.setMinutes(0);
47	this.setSeconds(0);
48	this.setMilliseconds(0);
49}
50
51function getDateFormat (date){
52	let day = `${date.getDate()}`.length == 1 ? `0${date.getDate()}` : date.getDate();
53	let month = `${date.getMonth()+1}`.length == 1 ? `0${date.getMonth()+1}` : date.getMonth()+1;
54	let year = date.getFullYear();
55	return `${day}/${month}/${year}`;
56}
57
58function getDateTimeFormat (date){
59	let day = `${date.getDate()}`.length == 1 ? `0${date.getDate()}` : date.getDate();
60	let month = `${date.getMonth()+1}`.length == 1 ? `0${date.getMonth()+1}` : date.getMonth()+1;
61	let year = date.getFullYear();
62	let hour = `${date.getHours()}`.length == 1 ? `0${date.getHours()}` : date.getHours();
63	let minute = `${date.getMinutes()}`.length == 1 ? `0${date.getMinutes()}` : date.getMinutes();
64	return `${day}/${month}/${year} ${hour}:${minute} น.`;
65}
66
67this.getPythonDateFormat = async function(date){
68	let day = `${date.getDate()}`.length == 1 ? `0${date.getDate()}` : date.getDate();
69	let month = `${date.getMonth()+1}`.length == 1 ? `0${date.getMonth()+1}` : date.getMonth()+1;
70	let year = date.getFullYear();
71	return `${year}-${month}-${day}`;
72}
73
74this.getPythonDateTimeFormat = async function(date){
75	let day = `${date.getDate()}`.length == 1 ? `0${date.getDate()}` : date.getDate();
76	let month = `${date.getMonth()+1}`.length == 1 ? `0${date.getMonth()+1}` : date.getMonth()+1;
77	let year = date.getFullYear();
78	let hour = `${date.getHours()}`.length == 1 ? `0${date.getHours()}` : date.getHours();
79	let minute = `${date.getMinutes()}`.length == 1 ? `0${date.getMinutes()}` : date.getMinutes();
80	let second = `${date.getSeconds()}`.length == 1 ? `0${date.getSeconds()}` : date.getSeconds();
81	return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
82}
83
84function dateToDateID(date) {
85	let now = new Date();
86	let DAY_SECONDS = 60 * 60 * 24 * 1000.0;
87	let timezone = (now.getTimezoneOffset() * 60) * 1000.0;
88	let datetime = new Date(date);
89	return parseInt((datetime.getTime() - timezone) / DAY_SECONDS)
90}
91
92function dateIDToDate(dateID) {
93	let now = new Date();
94	let DAY_SECONDS = 60 * 60 * 24 * 1000.0;
95	let timezone = (now.getTimezoneOffset() * 60) * 1000.0;
96	let timestamp = (dateID * DAY_SECONDS) + timezone;
97	let datetime = new Date(timestamp);
98	return datetime;
99}
100
101function dateToMonthID(date) {
102	return parseInt(12 * (date.getFullYear() - 1970) + (date.getMonth() + 1))
103}
104
105async function getDiffServerTime() {
106	const clientTimestamp = new Date().getTime();
107	let response = await GET(`utility/time/server/get/?clientTimestamp=${clientTimestamp}`);
108	let data = response.result;
109	const nowTimeStamp = new Date().getTime();
110	const serverClientRequestDiffTime = data.diff;
111	const serverTimestamp = data.serverTimestamp;
112
113	const serverClientResponseDiffTime = nowTimeStamp - serverTimestamp;
114	const responseTime = (serverClientRequestDiffTime - nowTimeStamp + clientTimestamp - serverClientResponseDiffTime ) / 2
115
116	return serverClientResponseDiffTime - responseTime;
117}
118
119async function getSyncedServerTime() {
120	const diff = await getDiffServerTime();
121	return new Date((new Date().getTime()) + diff);
122}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.