How to change timezone in test step

In my Pipeline test, it is necessary to change the time zone to Japan compliant.
Is there a simple way to change the time zone?

1 Like

Hi @kud-sta,

Depends on where you want to set the timezone.

If you want to set the system timezone, you can do that with a Script step, just like you would in your Terminal/Command Line.

E.g. in case of macOS: http://apple.stackexchange.com/questions/117994/is-there-a-fast-way-to-switch-system-time-zone-from-the-command-line

sudo systemsetup -settimezone timezone

Let us know if you have any questions!

1 Like

This works on macOS

sudo systemsetup -settimezone America/Denver

On Ubuntu, there’s an error

sudo timedatectl set-timezone America/Denver

Failed to create bus connection: No such file or directory

Is there a way to set the timezone on the Ubuntu containers?

Edit: I’m hoping this solution works
Edit2: nope :sob:

@bootstraponline what was the issue with https://serverfault.com/a/94996/221361 ?

There seem to be an even easier solution, setting the TZ environment variable (see e.g. https://github.com/moby/moby/issues/12084#issuecomment-160265752). Not sure if it’s respected by every tool / by the tool you want to use but it certainly is by date:

docker run --rm -it bitriseio/docker-bitrise-base bash

root@eb8b4223062f:/bitrise/src#

$ date
Fri Sep 15 12:29:27 UTC 2017

$ export TZ=Europe/London
$ date
Fri Sep 15 13:31:15 BST 2017

$ export TZ=Europe/Budapest
$ date
Fri Sep 15 14:31:50 CEST 2017

You can of course set the TZ env as an env var in the bitrise config / bitrise.yml, example:

format_version: "4"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: other
app:
  envs:
  - TZ: Europe/Budapest
trigger_map:
- push_branch: '*'
  workflow: primary
- pull_request_source_branch: '*'
  workflow: primary
workflows:
  primary:
    steps:
    - script@1.1.4:
        title: Do anything with Script step
        inputs:
        - content: date

Running it in the same docker container as above:

$ date
Fri Sep 15 12:35:46 UTC 2017

$ bitrise run primary

  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
  β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β•β•β•
  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
  β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β•šβ•β•β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•
  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
  β•šβ•β•β•β•β•β• β•šβ•β•   β•šβ•β•   β•šβ•β•  β•šβ•β•β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β•β•β•β•β•

  version: 1.8.0

INFO[12:35:57] bitrise runs in CI mode           
INFO[12:35:57] Running workflow: primary         

Switching to workflow: primary

+------------------------------------------------------------------------------+
| (0) Do anything with Script step                                             |
+------------------------------------------------------------------------------+
| id: script                                                                   |
| version: 1.1.4                                                               |
| collection: https://github.com/bitrise-io/bitrise-steplib.git                |
| toolkit: bash                                                                |
| time: 2017-09-15T12:35:58Z                                                   |
+------------------------------------------------------------------------------+
|                                                                              |
Fri Sep 15 14:35:58 CEST 2017
|                                                                              |
+---+---------------------------------------------------------------+----------+
| βœ“ | Do anything with Script step                                  | 0.51 sec |
+---+---------------------------------------------------------------+----------+


+------------------------------------------------------------------------------+
|                               bitrise summary                                |
+---+---------------------------------------------------------------+----------+
|   | title                                                         | time (s) |
+---+---------------------------------------------------------------+----------+
| βœ“ | Do anything with Script step                                  | 0.51 sec |
+---+---------------------------------------------------------------+----------+
| Total runtime: 0.51 sec                                                      |
+------------------------------------------------------------------------------+

I’m not sure. We are using jest snapshots and no method of changing the timezone is helping. Here’s an example failure:

-                       May 31, 2037 at 11:59 PM
+                       Jun 1, 2037 at 5:59 AM

The jest tests depend on the system time zone. The mac command works fine, linux one doesn’t.

https://www.bitrise.io/build/7a47135bdb46c9c0

#!/usr/bin/env bash -e

rm /etc/timezone   
rm /etc/localtime

TIMEZONE="America/Denver"      
export TZ="$TIMEZONE"
echo "$TIMEZONE" > /etc/timezone                     
cp "/usr/share/zoneinfo/${TIMEZONE}" /etc/localtime 
dpkg-reconfigure -f noninteractive tzdata

This is what I’m using now & it worked for me.

Current default time zone: 'America/Denver'
Local time is now:      Fri Sep 15 08:52:42 MDT 2017.
Universal Time is now:  Fri Sep 15 14:52:42 UTC 2017.
2 Likes

Glad to hear and thanks for reporting @bootstraponline! :slight_smile:

worked with me :call_me_hand: :call_me_hand:

1 Like