Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Python: Bug: TimePlugin timeZoneOffset and timeZoneName always return an empty string

Đã đóng Phù hợp với người mới
#14,583 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 5 ngày

@jeevan1098 đang làm issue này rồi.

Từ ngày 15/10/2026.

  • #14604 của @jeevan1098 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
80/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
ai

Hướng nghiên cứu

Lỗi nằm ở python/semantic_kernel/core_plugins/time_plugin.py, trong time_zone_offset và time_zone_name. Hai hàm này gọi datetime.datetime.now() không kèm múi giờ nên nhận về %z và %Z rỗng. Hãy đọc các unit test hiện có của TimePlugin, nơi test_mock_now patch now bằng một giá trị có múi giờ UTC, rồi tái hiện lỗi bằng đoạn mã trong issue. Hoàn thành khi cả hai hàm trả về độ lệch múi giờ và tên múi giờ cục bộ khi được gọi với đồng hồ không có múi giờ, và có một test bao phủ đường đi này mà không dùng mock có múi giờ UTC.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

python triage

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)
Ngôn ngữ chính
C#
Star
28.7k
Fork
4.8k
Merge trung bình
6 ngày 5 giờ
Pull request đã merge (30 ngày)
53

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/semantic-kernel

Tất cả issue của microsoft/semantic-kernel

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.