File size: 6,507 Bytes
5443195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// HuggingBot Module: Time Zone Converter
(function(MS){
  MS.register("timezone", {
    name: "Time Zone Converter",
    description: "Get current time anywhere, convert times between time zones.",
    tools: [
      {
        type: "function",
        function: {
          name: "get_time",
          description: "Get current time in any city or time zone. Use 'all' to see times around the world.",
          parameters: {
            type: "object",
            properties: {
              location: { type: "string", description: "City name (e.g. 'Tokyo'), timezone (e.g. 'Asia/Tokyo'), or 'all'" }
            },
            required: ["location"]
          }
        }
      },
      {
        type: "function",
        function: {
          name: "convert_time",
          description: "Convert a time between two time zones.",
          parameters: {
            type: "object",
            properties: {
              time: { type: "string", description: "Time like '3:00 PM' or 'now'" },
              from_zone: { type: "string", description: "Source timezone or city" },
              to_zone: { type: "string", description: "Target timezone or city" }
            },
            required: ["time", "from_zone", "to_zone"]
          }
        }
      }
    ],
    handleToolCall: async function(tn, args) {
      if (tn === "get_time") {
        try {
          var loc = (args.location || "").trim().toLowerCase();
          if (loc === "all") {
            var cities = ["New York", "London", "Tokyo", "Sydney", "Dubai", "Paris", "Los Angeles", "Singapore", "Mumbai", "Berlin", "Toronto", "São Paulo", "Seoul", "Cairo", "Mexico City"];
            var lines = ["## 🌍 World Clock", ""];
            for (var i = 0; i < cities.length; i++) {
              try {
                var tzMap = {
                  "new york": "America/New_York", "london": "Europe/London", "tokyo": "Asia/Tokyo",
                  "sydney": "Australia/Sydney", "dubai": "Asia/Dubai", "paris": "Europe/Paris",
                  "los angeles": "America/Los_Angeles", "singapore": "Asia/Singapore", "mumbai": "Asia/Kolkata",
                  "berlin": "Europe/Berlin", "toronto": "America/Toronto", "são paulo": "America/Sao_Paulo",
                  "seoul": "Asia/Seoul", "cairo": "Africa/Cairo", "mexico city": "America/Mexico_City"
                };
                var tz = tzMap[cities[i].toLowerCase()] || "UTC";
                var time = new Date().toLocaleString("en-US", { timeZone: tz, hour: "2-digit", minute: "2-digit", hour12: true });
                var date = new Date().toLocaleDateString("en-US", { timeZone: tz, weekday: "short", month: "short", day: "numeric" });
                lines.push("**" + cities[i] + "** — " + time + " (" + date + ")");
              } catch(e2) {
                lines.push("**" + cities[i] + "** — unavailable");
              }
            }
            return lines.join("\n");
          } else {
            var tzMap = {
              "new york": "America/New_York", "london": "Europe/London", "tokyo": "Asia/Tokyo",
              "sydney": "Australia/Sydney", "dubai": "Asia/Dubai", "paris": "Europe/Paris",
              "los angeles": "America/Los_Angeles", "chicago": "America/Chicago", "denver": "America/Denver",
              "singapore": "Asia/Singapore", "mumbai": "Asia/Kolkata", "berlin": "Europe/Berlin",
              "toronto": "America/Toronto", "seoul": "Asia/Seoul", "beijing": "Asia/Shanghai",
              "hong kong": "Asia/Hong_Kong", "moscow": "Europe/Moscow", "istanbul": "Europe/Istanbul",
              "rome": "Europe/Rome", "madrid": "Europe/Madrid", "amsterdam": "Europe/Amsterdam",
              "bangkok": "Asia/Bangkok", "lagos": "Africa/Lagos", "nairobi": "Africa/Nairobi",
              "auckland": "Pacific/Auckland", "honolulu": "Pacific/Honolulu", "anchorage": "America/Anchorage",
              "cairo": "Africa/Cairo", "jakarta": "Asia/Jakarta", "karachi": "Asia/Karachi",
              "dhaka": "Asia/Dhaka", "manila": "Asia/Manila", "kolkata": "Asia/Kolkata",
              "são paulo": "America/Sao_Paulo", "mexico city": "America/Mexico_City",
              "buenos aires": "America/Argentina/Buenos_Aires", "santiago": "America/Santiago"
            };
            var tz = tzMap[loc] || loc;
            try {
              var time = new Date().toLocaleString("en-US", { timeZone: tz, hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: true });
              var date = new Date().toLocaleDateString("en-US", { timeZone: tz, weekday: "long", year: "numeric", month: "long", day: "numeric" });
              return "## 🕐 Time in " + args.location + "\n\n**" + time + "**\n" + date + "";
            } catch(e) {
              return "Time unavailable for \"" + args.location + "\". Try a city name or IANA timezone (e.g., 'America/New_York').";
            }
          }
        } catch(e) { return "Error: " + e.message; }
      }

      if (tn === "convert_time") {
        try {
          var inputTime = (args.time || "").trim().toLowerCase();
          var fromZone = (args.from_zone || "").trim();
          var toZone = (args.to_zone || "").trim();
          if (!inputTime || !fromZone || !toZone) return "Please provide a time, source timezone, and target timezone.";

          if (inputTime === "now") {
            var now = new Date();
            var fromTime = now.toLocaleString("en-US", { timeZone: fromZone, hour: "2-digit", minute: "2-digit", hour12: true });
            var toTime = now.toLocaleString("en-US", { timeZone: toZone, hour: "2-digit", minute: "2-digit", hour12: true });
            var fromDate = now.toLocaleDateString("en-US", { timeZone: fromZone, weekday: "short", month: "short", day: "numeric" });
            var toDate = now.toLocaleDateString("en-US", { timeZone: toZone, weekday: "short", month: "short", day: "numeric" });
            return "## 🔄 Time Conversion\n\n**Now** in **" + fromZone + "**: " + fromTime + " (" + fromDate + ")\n**Now** in **" + toZone + "**: " + toTime + " (" + toDate + ")";
          } else {
            return "⏰ Convert \"" + inputTime + "\" from " + fromZone + " to " + toZone + "\n\nFor precise time conversion, please use 'now' or provide a specific time like '3:00 PM'.\n\n*Tip: Timezone conversion uses IANA timezone names like 'America/New_York' or 'Europe/London'.*";
          }
        } catch(e) { return "Conversion error: " + e.message; }
      }
      return null;
    }
  });
})(ModuleSystem);