|
| 1 | +import datetime |
| 2 | + |
| 3 | +from semantic_kernel.skill_definition import sk_function |
| 4 | + |
| 5 | + |
| 6 | +class TimeSkill: |
| 7 | + """ |
| 8 | + Description: TimeSkill provides a set of functions |
| 9 | + to get the current time and date. |
| 10 | +
|
| 11 | + Usage: |
| 12 | + kernel.import_skill("time", TimeSkill()) |
| 13 | +
|
| 14 | + Examples: |
| 15 | + {{time.date}} => Sunday, 12 January, 2031 |
| 16 | + {{time.today}} => Sunday, 12 January, 2031 |
| 17 | + {{time.now}} => Sunday, January 12, 2031 9:15 PM |
| 18 | + {{time.utcNow}} => Sunday, January 13, 2031 5:15 AM |
| 19 | + {{time.time}} => 09:15:07 PM |
| 20 | + {{time.year}} => 2031 |
| 21 | + {{time.month}} => January |
| 22 | + {{time.monthNumber}} => 01 |
| 23 | + {{time.day}} => 12 |
| 24 | + {{time.dayOfWeek}} => Sunday |
| 25 | + {{time.hour}} => 9 PM |
| 26 | + {{time.hourNumber}} => 21 |
| 27 | + {{time.minute}} => 15 |
| 28 | + {{time.minutes}} => 15 |
| 29 | + {{time.second}} => 7 |
| 30 | + {{time.seconds}} => 7 |
| 31 | + {{time.timeZoneOffset}} => -0800 |
| 32 | + {{time.timeZoneName}} => PST |
| 33 | + """ |
| 34 | + |
| 35 | + @sk_function(description="Get the current time.") |
| 36 | + def date(self) -> str: |
| 37 | + """ |
| 38 | + Get the current date |
| 39 | +
|
| 40 | + Example: |
| 41 | + {{time.date}} => Sunday, 12 January, 2031 |
| 42 | + """ |
| 43 | + now = datetime.datetime.now() |
| 44 | + return now.strftime("%A, %d %B, %Y") |
| 45 | + |
| 46 | + @sk_function(description="Get the current date and time in the local time zone") |
| 47 | + def now(self) -> str: |
| 48 | + """ |
| 49 | + Get the current date and time in the local time zone" |
| 50 | +
|
| 51 | + Example: |
| 52 | + {{time.now}} => Sunday, January 12, 2031 9:15 PM |
| 53 | + """ |
| 54 | + now = datetime.datetime.now() |
| 55 | + return now.strftime("%A, %B %d, %Y %I:%M %p") |
| 56 | + |
| 57 | + @sk_function(description="Get the current date and time in UTC", name="utcNow") |
| 58 | + def utc_now(self) -> str: |
| 59 | + """ |
| 60 | + Get the current date and time in UTC |
| 61 | +
|
| 62 | + Example: |
| 63 | + {{time.utcNow}} => Sunday, January 13, 2031 5:15 AM |
| 64 | + """ |
| 65 | + now = datetime.datetime.utcnow() |
| 66 | + return now.strftime("%A, %B %d, %Y %I:%M %p") |
| 67 | + |
| 68 | + @sk_function(description="Get the current time in the local time zone") |
| 69 | + def time(self) -> str: |
| 70 | + """ |
| 71 | + Get the current time in the local time zone |
| 72 | +
|
| 73 | + Example: |
| 74 | + {{time.time}} => 09:15:07 PM |
| 75 | + """ |
| 76 | + now = datetime.datetime.now() |
| 77 | + return now.strftime("%I:%M:%S %p") |
| 78 | + |
| 79 | + @sk_function(description="Get the current year") |
| 80 | + def year(self) -> str: |
| 81 | + """ |
| 82 | + Get the current year |
| 83 | +
|
| 84 | + Example: |
| 85 | + {{time.year}} => 2031 |
| 86 | + """ |
| 87 | + now = datetime.datetime.now() |
| 88 | + return now.strftime("%Y") |
| 89 | + |
| 90 | + @sk_function(description="Get the current month") |
| 91 | + def month(self) -> str: |
| 92 | + """ |
| 93 | + Get the current month |
| 94 | +
|
| 95 | + Example: |
| 96 | + {{time.month}} => January |
| 97 | + """ |
| 98 | + now = datetime.datetime.now() |
| 99 | + return now.strftime("%B") |
| 100 | + |
| 101 | + @sk_function(description="Get the current month number") |
| 102 | + def month_number(self) -> str: |
| 103 | + """ |
| 104 | + Get the current month number |
| 105 | +
|
| 106 | + Example: |
| 107 | + {{time.monthNumber}} => 01 |
| 108 | + """ |
| 109 | + now = datetime.datetime.now() |
| 110 | + return now.strftime("%m") |
| 111 | + |
| 112 | + @sk_function(description="Get the current day") |
| 113 | + def day(self) -> str: |
| 114 | + """ |
| 115 | + Get the current day of the month |
| 116 | +
|
| 117 | + Example: |
| 118 | + {{time.day}} => 12 |
| 119 | + """ |
| 120 | + now = datetime.datetime.now() |
| 121 | + return now.strftime("%d") |
| 122 | + |
| 123 | + @sk_function(description="Get the current day of the week", name="dayOfWeek") |
| 124 | + def day_of_week(self) -> str: |
| 125 | + """ |
| 126 | + Get the current day of the week |
| 127 | +
|
| 128 | + Example: |
| 129 | + {{time.dayOfWeek}} => Sunday |
| 130 | + """ |
| 131 | + now = datetime.datetime.now() |
| 132 | + return now.strftime("%A") |
| 133 | + |
| 134 | + @sk_function(description="Get the current hour") |
| 135 | + def hour(self) -> str: |
| 136 | + """ |
| 137 | + Get the current hour |
| 138 | +
|
| 139 | + Example: |
| 140 | + {{time.hour}} => 9 PM |
| 141 | + """ |
| 142 | + now = datetime.datetime.now() |
| 143 | + return now.strftime("%I %p") |
| 144 | + |
| 145 | + @sk_function(description="Get the current hour number", name="hourNumber") |
| 146 | + def hour_number(self) -> str: |
| 147 | + """ |
| 148 | + Get the current hour number |
| 149 | +
|
| 150 | + Example: |
| 151 | + {{time.hourNumber}} => 21 |
| 152 | + """ |
| 153 | + now = datetime.datetime.now() |
| 154 | + return now.strftime("%H") |
| 155 | + |
| 156 | + @sk_function(description="Get the current minute") |
| 157 | + def minute(self) -> str: |
| 158 | + """ |
| 159 | + Get the current minute |
| 160 | +
|
| 161 | + Example: |
| 162 | + {{time.minute}} => 15 |
| 163 | + """ |
| 164 | + now = datetime.datetime.now() |
| 165 | + return now.strftime("%M") |
| 166 | + |
| 167 | + @sk_function(description="Get the seconds on the current minute") |
| 168 | + def second(self) -> str: |
| 169 | + """ |
| 170 | + Get the seconds on the current minute |
| 171 | +
|
| 172 | + Example: |
| 173 | + {{time.second}} => 7 |
| 174 | + """ |
| 175 | + now = datetime.datetime.now() |
| 176 | + return now.strftime("%S") |
| 177 | + |
| 178 | + @sk_function(description="Get the current time zone offset", name="timeZoneOffset") |
| 179 | + def time_zone_offset(self) -> str: |
| 180 | + """ |
| 181 | + Get the current time zone offset |
| 182 | +
|
| 183 | + Example: |
| 184 | + {{time.timeZoneOffset}} => -08:00 |
| 185 | + """ |
| 186 | + now = datetime.datetime.now() |
| 187 | + return now.strftime("%z") |
| 188 | + |
| 189 | + @sk_function(description="Get the current time zone name", name="timeZoneName") |
| 190 | + def time_zone_name(self) -> str: |
| 191 | + """ |
| 192 | + Get the current time zone name |
| 193 | +
|
| 194 | + Example: |
| 195 | + {{time.timeZoneName}} => PST |
| 196 | + """ |
| 197 | + now = datetime.datetime.now() |
| 198 | + return now.strftime("%Z") |
0 commit comments