Python: Bug: TimePlugin timeZoneOffset and timeZoneName always return an empty string
Maintainers usually reply within 3 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 80/100
Research direction
The bug is in python/semantic_kernel/core_plugins/time_plugin.py, in time_zone_offset and time_zone_name, which call datetime.datetime.now() without a timezone and so get an empty %z and %Z. Read the existing unit tests for TimePlugin, where test_mock_now patches now with a UTC-aware value, and reproduce with the snippet in the issue. Done when both functions return the local offset and zone name for a naive-clock call, and a test covers that path without the aware-UTC mock.
Written by the indexing model from the issue text.
Description
Describe the bug
TimePlugin.timeZoneOffset and TimePlugin.timeZoneName always return an empty string.
Where
python/semantic_kernel/core_plugins/time_plugin.py:
@kernel_function(description="Get the current time zone offset", name="timeZoneOffset")
def time_zone_offset(self) -> str:
"""... {{time.timeZoneOffset}} => -08:00"""
now = datetime.datetime.now()
return now.strftime("%z")
@kernel_function(description="Get the current time zone name", name="timeZoneName")
def time_zone_name(self) -> str:
"""... {{time.timeZoneName}} => PST"""
now = datetime.datetime.now()
return now.strftime("%Z")
datetime.datetime.now() without a tz argument returns a naive datetime. For a naive datetime strftime("%z") and strftime("%Z") return "".
The existing unit tests do not catch this because they patch datetime.datetime.now to return a timezone-aware UTC value (test_mock_now), which never happens in real use.
To reproduce
Checked on current main (1b1f64b98), Python 3.13, Windows, local zone US Eastern.
import datetime
from semantic_kernel.core_plugins.time_plugin import TimePlugin
t = TimePlugin()
print(repr(t.time_zone_offset()), repr(t.time_zone_name()))
now = datetime.datetime.now().astimezone()
print(repr(now.strftime("%z")), repr(now.strftime("%Z")))
Actual:
'' ''
'-0400' 'Eastern Daylight Time'
A prompt template such as Time zone: {{time.timeZoneName}} ({{time.timeZoneOffset}}) renders as Time zone: ().
Expected
Both functions return the local zone offset and name. Using datetime.datetime.now().astimezone() gives an aware datetime in the local zone, so %z and %Z are filled.
I have a fix with tests ready and will open a PR for this.
Platform
- Language: Python
- Source: main branch of the repository (1b1f64b98)
- Dominant language
- C#
- Stars
- 28.6k
- Forks
- 4.8k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 20
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/semantic-kernel
-
Python: Bug: AnnotationContent and StreamingAnnotationContent to_element writes CitationType.X, so annotations in a rendered chat history fail to parsePossibly taken @CRYPTONIKAV claimed this 2 days ago. Openpython triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
microsoft/semantic-kernel#14590 ·
Maintainers usually reply within 3 days
-
.Net: gpt-image-1 is the default image model in the .NET OpenAI connector, and OpenAI shuts it down on October 23Possibly taken @nightcityblade claimed this 13 days ago. Open.NET triage
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
microsoft/semantic-kernel#14526 · 1 comment ·
Maintainers usually reply within 3 days
-
Python: VolatileMemoryStore.get_batch and get_nearest_matches ignore with_embeddings=False (deepcopy result is discarded)Possibly taken @VANDRANKI claimed this 14 days ago. Openpython triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
microsoft/semantic-kernel#14522 ·
Maintainers usually reply within 3 days
-
Python: VolatileMemoryStore.get_nearest_match returns an un-awaited coroutine instead of a (MemoryRecord, score) tuplePossibly taken @VANDRANKI claimed this 14 days ago. Openpython triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
microsoft/semantic-kernel#14521 ·
Maintainers usually reply within 3 days
-
.Net: Bug: BinaryContent does not decode the %xx escapes of a non-base64 data URIPossibly taken @Laurianti claimed this 14 days ago. Open.NET triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
microsoft/semantic-kernel#14518 ·
Maintainers usually reply within 3 days
All issues in microsoft/semantic-kernel
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
good first issue help wanted ready-for-human
Difficulty 2/5 Half a day Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
ready-for-agent size:S status:todo
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
elsa-workflows/elsa-foundation#2830 ·
Maintainers usually reply within 1 day
-
Review - Maintainer WG-Maintainers-Build
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
PowerShell/PowerShell#28220 · 1 comment ·
Maintainers usually reply within 1 day
-
area: docs eco: dotnet good first issue help wanted lane: free-agent roadmap size: XS type: docs
Difficulty 2/5 Under an hour Newbie friendliness 72/100
arminazimi/evergreen#377 ·
Maintainers usually reply within 1 day