sai-utc-to-ist-time 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # utc-to-ist
2
+
3
+ A lightweight JavaScript utility to convert UTC time to IST (Indian Standard Time) and vice versa. No dependencies, works in both Node.js and browser environments.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/utc-to-ist.svg)](https://www.npmjs.com/package/utc-to-ist)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Features
9
+
10
+ - 🚀 Zero dependencies
11
+ - 📦 Lightweight (~1KB)
12
+ - 🔄 Bidirectional conversion (UTC ↔ IST)
13
+ - 🎯 Simple and intuitive API
14
+ - 💪 TypeScript support
15
+ - 🌐 Works in Node.js and browsers
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install utc-to-ist
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### Basic Usage
26
+
27
+ ```javascript
28
+ const { utcToIst, istToUtc, formatIst } = require("utc-to-ist");
29
+
30
+ // Convert current UTC time to IST
31
+ const istTime = utcToIst();
32
+ console.log(istTime); // Date object in IST
33
+
34
+ // Convert specific UTC time to IST
35
+ const specificIstTime = utcToIst("2026-01-28T10:00:00Z");
36
+ console.log(specificIstTime); // 2026-01-28T15:30:00.000Z (IST)
37
+
38
+ // Convert IST to UTC
39
+ const utcTime = istToUtc("2026-01-28T15:30:00");
40
+ console.log(utcTime); // 2026-01-28T10:00:00.000Z (UTC)
41
+
42
+ // Get formatted IST string
43
+ const formatted = formatIst("2026-01-28T10:00:00Z");
44
+ console.log(formatted); // "2026-01-28 15:30:00"
45
+ ```
46
+
47
+ ### ES6 Module
48
+
49
+ ```javascript
50
+ import { utcToIst, istToUtc, formatIst } from "utc-to-ist";
51
+
52
+ const istTime = utcToIst();
53
+ ```
54
+
55
+ ### Browser Usage
56
+
57
+ ```html
58
+ <script src="node_modules/utc-to-ist/index.js"></script>
59
+ <script>
60
+ // Functions are available globally on the window object
61
+ console.log(formatIst());
62
+ console.log(utcToIst());
63
+ console.log(istToUtc());
64
+ </script>
65
+ ```
66
+
67
+ ## API Reference
68
+
69
+ ### `utcToIst(date?)`
70
+
71
+ Converts UTC time to IST (adds 5 hours 30 minutes).
72
+
73
+ **Parameters:**
74
+
75
+ - `date` (optional): Date object, date string, or timestamp. Defaults to current time.
76
+
77
+ **Returns:** Date object representing the IST time.
78
+
79
+ **Example:**
80
+
81
+ ```javascript
82
+ utcToIst(); // Current time in IST
83
+ utcToIst("2026-01-28T10:00:00Z"); // Specific UTC time to IST
84
+ utcToIst(new Date()); // Date object to IST
85
+ utcToIst(1706437200000); // Timestamp to IST
86
+ ```
87
+
88
+ ### `istToUtc(date?)`
89
+
90
+ Converts IST time to UTC (subtracts 5 hours 30 minutes).
91
+
92
+ **Parameters:**
93
+
94
+ - `date` (optional): Date object, date string, or timestamp. Defaults to current time.
95
+
96
+ **Returns:** Date object representing the UTC time.
97
+
98
+ **Example:**
99
+
100
+ ```javascript
101
+ istToUtc(); // Current time in UTC
102
+ istToUtc("2026-01-28T15:30:00"); // Specific IST time to UTC
103
+ istToUtc(new Date()); // Date object to UTC
104
+ ```
105
+
106
+ ### `formatIst(date?)`
107
+
108
+ Converts UTC time to IST and returns a formatted string.
109
+
110
+ **Parameters:**
111
+
112
+ - `date` (optional): Date object, date string, or timestamp. Defaults to current time.
113
+
114
+ **Returns:** String in format `YYYY-MM-DD HH:MM:SS` (IST).
115
+
116
+ **Example:**
117
+
118
+ ```javascript
119
+ formatIst(); // "2026-01-28 15:30:00"
120
+ formatIst("2026-01-28T10:00:00Z"); // "2026-01-28 15:30:00"
121
+ ```
122
+
123
+ ## TypeScript Support
124
+
125
+ This package includes TypeScript definitions:
126
+
127
+ ```typescript
128
+ import { utcToIst, istToUtc, formatIst } from "utc-to-ist";
129
+
130
+ const istTime: Date = utcToIst();
131
+ const utcTime: Date = istToUtc();
132
+ const formatted: string = formatIst();
133
+ ```
134
+
135
+ ## How It Works
136
+
137
+ IST (Indian Standard Time) is UTC+5:30. This package:
138
+
139
+ - **UTC to IST**: Adds 5 hours and 30 minutes (19,800,000 milliseconds)
140
+ - **IST to UTC**: Subtracts 5 hours and 30 minutes (19,800,000 milliseconds)
141
+
142
+ ## Use Cases
143
+
144
+ - Converting server timestamps (UTC) to Indian local time
145
+ - Displaying IST time in web applications
146
+ - Logging events in IST timezone
147
+ - Scheduling tasks based on IST
148
+ - Converting user input from IST to UTC for storage
149
+
150
+ ## License
151
+
152
+ MIT © Sai
153
+
154
+ ## Contributing
155
+
156
+ Contributions are welcome! Please feel free to submit a Pull Request.
157
+
158
+ ## Issues
159
+
160
+ If you find any bugs or have feature requests, please create an issue on [GitHub](https://github.com/sainath-666/utc-to-ist/issues).
161
+
162
+ ## Changelog
163
+
164
+ ### 1.0.0
165
+
166
+ - Initial release
167
+ - UTC to IST conversion
168
+ - IST to UTC conversion
169
+ - Formatted IST output
package/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Converts UTC time to IST (Indian Standard Time)
3
+ * @param date - Date object, date string, or timestamp. Defaults to current time.
4
+ * @returns Date object representing the IST time
5
+ */
6
+ export function utcToIst(date?: Date | string | number): Date;
7
+
8
+ /**
9
+ * Converts IST (Indian Standard Time) to UTC
10
+ * @param date - Date object, date string, or timestamp. Defaults to current time.
11
+ * @returns Date object representing the UTC time
12
+ */
13
+ export function istToUtc(date?: Date | string | number): Date;
14
+
15
+ /**
16
+ * Converts UTC time to IST and returns a formatted string
17
+ * @param date - Date object, date string, or timestamp. Defaults to current time.
18
+ * @returns Formatted string in format "YYYY-MM-DD HH:MM:SS" (IST)
19
+ */
20
+ export function formatIst(date?: Date | string | number): string;
package/index.js ADDED
@@ -0,0 +1,29 @@
1
+ function utcToIst(date = new Date()) {
2
+ const utc = new Date(date);
3
+ return new Date(utc.getTime() + 5.5 * 60 * 60 * 1000);
4
+ }
5
+
6
+ function istToUtc(date = new Date()) {
7
+ const ist = new Date(date);
8
+ return new Date(ist.getTime() - 5.5 * 60 * 60 * 1000);
9
+ }
10
+
11
+ function formatIst(date = new Date()) {
12
+ return utcToIst(date).toISOString().replace("T", " ").slice(0, 19);
13
+ }
14
+
15
+ // Support for CommonJS (Node.js) and Browser
16
+ if (typeof module !== "undefined" && module.exports) {
17
+ module.exports = {
18
+ utcToIst,
19
+ istToUtc,
20
+ formatIst,
21
+ };
22
+ } else {
23
+ // Support for Browser (Global Scope)
24
+ if (typeof window !== "undefined") {
25
+ window.utcToIst = utcToIst;
26
+ window.istToUtc = istToUtc;
27
+ window.formatIst = formatIst;
28
+ }
29
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "sai-utc-to-ist-time",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight JavaScript utility to convert UTC time to IST (Indian Standard Time) and vice versa",
5
+ "keywords": [
6
+ "utc",
7
+ "ist",
8
+ "timezone",
9
+ "time-conversion",
10
+ "indian-standard-time",
11
+ "datetime",
12
+ "time",
13
+ "converter",
14
+ "india"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/sainath-666/utc-to-ist.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/sainath-666/utc-to-ist/issues"
22
+ },
23
+ "homepage": "https://github.com/sainath-666/utc-to-ist#readme",
24
+ "license": "MIT",
25
+ "author": "Sai",
26
+ "type": "commonjs",
27
+ "main": "index.js",
28
+ "types": "index.d.ts",
29
+ "files": [
30
+ "index.js",
31
+ "index.d.ts",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "scripts": {
36
+ "test": "node test.js"
37
+ },
38
+ "engines": {
39
+ "node": ">=12.0.0"
40
+ }
41
+ }