benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 3e679c76-480f-5f4f-a722-d33cb0b3b4c7

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

from datetime import datetime
import pytz
import re
from faker import Faker


def task_func(epoch_milliseconds, seed=0, timezones=["UTC"]):
    """Create a dictionary with a fake event schedule given an event time.

    The function converts a given epoch in milliseconds into a datetime object in
    the current system time's timezone. It generates a fake event name using Faker. 
    Then, it uses pytz and regex to check if specified timezones are valid (i.e. 
    in pytz.all_timezones or can be parsed using regex from UTC±HH:MM format), ignoring 
    invalid ones. If none is valid or if timezones were not specified, it selects UTC; 
    otherwise, it randomly selects a valid one using Faker. Finally, the function returns a 
    dictionary with the fake event name as key and a list as value, where the list itself 
    contains a schedule, i.e. a dictionary with keys 'date', 'time', 'timezone'.

    Parameters:
    - epoch_milliseconds (int): Epoch time in milliseconds. If negative, defaults to 0.
    - seed (int, optional): Random seed for Faker's RNG. Defaults to None.
    - timezones (list, optional): A list of timezones to select from.
                                  If none is valid or if not specified, defaults to ['UTC'].

    Returns:
    - A dictionary containing event names as keys and a list of event details as values.
      Event details include the date, time, and timezone of the event.

    Requirements:
    - datetime.datetime
    - faker
    - pytz
    - re

    Example:
    >>> task_func(1236472051807, seed=42)
    {'Danielle': [{'date': datetime.date(2009, 3, 8), 'time': datetime.time(11, 27, 31, 807000), 'timezone': 'UTC'}]}
    >>> task_func(1609459200000, seed=24, timezones=['UTC', 'UTC+01:00'])
    {'Jennifer': [{'date': datetime.date(2021, 1, 1), 'time': datetime.time(11, 0), 'timezone': 'UTC'}]}
    """

instruct prompt

Create a dictionary with a fake event schedule given an event time. The function converts a given epoch in milliseconds into a datetime object in the current system time's timezone. It generates a fake event name using Faker. Then, it uses pytz and regex to check if specified timezones are valid (i.e. in pytz.all_timezones or can be parsed using regex from UTC±HH:MM format), ignoring invalid ones. If none is valid or if timezones were not specified, it selects UTC; otherwise, it randomly selects a valid one using Faker. Finally, the function returns a dictionary with the fake event name as key and a list as value, where the list itself contains a schedule, i.e. a dictionary with keys 'date', 'time', 'timezone'.
The function should output with:
    A dictionary containing event names as keys and a list of event details as values.
    Event details include the date, time, and timezone of the event.
You should write self-contained code starting with:

Code

from datetime import datetime
import pytz
import re
from faker import Faker
def task_func(epoch_milliseconds, seed=0, timezones=["UTC"]):

code prompt

Code

from datetime import datetime
import pytz
import re
from faker import Faker
def task_func(epoch_milliseconds, seed=0, timezones=["UTC"]):

entry point

task_func

libs

  • pytz
  • faker
  • datetime
  • re

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import