Skip to content

Conversation

shaohuzhang1
Copy link
Contributor

fix: Workflow publishing name time error

Copy link

f2c-ci-robot bot commented Sep 3, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

f2c-ci-robot bot commented Sep 3, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaohuzhang1 shaohuzhang1 merged commit 410101e into v2 Sep 3, 2025
3 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_publish branch September 3, 2025 07:08
name=timezone.localtime(timezone.now()).strftime('%Y-%m-%d %H:%M:%S'),
publish_user_id=user_id,
publish_user_name=user.username,
workspace_id=workspace_id)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The publish method currently saves the current time in UTC using timezone.now(). This means that if you're working in a system where daylight saving time (DST) is applicable, your save time will be different from local time.

To avoid this discrepancy, use timezone.localtime(timezone.now()) to ensure the save time matches the user's location. Here’s how you can update your code:

def publish(self, instance, with_valid=True):
    application.is_publish = True
    application.save()

    # Use timezone localtime instead of utcnow for correct saved date and time
    work_flow_version = ApplicationVersion(
        work_flow=application.work_flow,
        application=application,
        name=datetime.strftime(application.created_at.astimezone(datetime.now().astimezone(tzinfo=None)), '%Y-%m-%d %H:%M:%S'), 
        publish_user_id=user_id,
        publish_user_name=user.username,
        workspace_id=workspace_id
    )

This change uses the created_at field on ApplicationInstance to get the timestamp which aligns better with what you might want to use when publishing something related to an instance creation date or event datetime, rather than always referring to now which could skew based on DST boundaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant